Commit 5e0b197a by Maarten L. Hekkelman

mmcif::Atom::compound() revision

parent af721eb1
...@@ -13,3 +13,4 @@ msvc/ ...@@ -13,3 +13,4 @@ msvc/
Testing/ Testing/
rsrc/feature-request.txt rsrc/feature-request.txt
test/1cbs.cif test/1cbs.cif
test/test-create_sugar_2.cif
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
# set the project name # set the project name
project(cifpp VERSION 4.0.0 LANGUAGES CXX) project(cifpp VERSION 4.1.0 LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
......
Version 4.1.0
- Some interface changes for mmcif::Atom
Version 4.0.0 Version 4.0.0
- getResidue in mmcif::Structure now requires both a - getResidue in mmcif::Structure now requires both a
sequence ID and an auth sequence ID. As a result the code was cleaned sequence ID and an auth sequence ID. As a result the code was cleaned
......
...@@ -80,7 +80,7 @@ class Atom ...@@ -80,7 +80,7 @@ class Atom
void moveTo(const Point &p); void moveTo(const Point &p);
const Compound &comp() const; const Compound *compound() const;
const std::string get_property(const std::string_view name) const; const std::string get_property(const std::string_view name) const;
void set_property(const std::string_view name, const std::string &value); void set_property(const std::string_view name, const std::string &value);
...@@ -186,7 +186,7 @@ class Atom ...@@ -186,7 +186,7 @@ class Atom
bool isSymmetryCopy() const { return impl().mSymmetryCopy; } bool isSymmetryCopy() const { return impl().mSymmetryCopy; }
std::string symmetry() const { return impl().mSymmetryOperator; } std::string symmetry() const { return impl().mSymmetryOperator; }
const Compound &comp() const { return impl().comp(); } const Compound &compound() const;
bool isWater() const { return impl().mCompID == "HOH" or impl().mCompID == "H2O" or impl().mCompID == "WAT"; } bool isWater() const { return impl().mCompID == "HOH" or impl().mCompID == "H2O" or impl().mCompID == "WAT"; }
int charge() const; int charge() const;
......
...@@ -148,19 +148,10 @@ int Atom::AtomImpl::charge() const ...@@ -148,19 +148,10 @@ int Atom::AtomImpl::charge() const
if (not formalCharge.has_value()) if (not formalCharge.has_value())
{ {
try auto c = compound();
{
auto &compound = comp();
if (compound.atoms().size() == 1) if (c != nullptr and c->atoms().size() == 1)
formalCharge = compound.atoms().front().charge; formalCharge = c->atoms().front().charge;
}
catch (const std::exception &ex)
{
if (cif::VERBOSE > 0)
std::cerr << "Error when trying to get charge of atom: " << ex.what() << std::endl;
formalCharge = 0;
}
} }
return formalCharge.value_or(0); return formalCharge.value_or(0);
...@@ -188,23 +179,16 @@ void Atom::AtomImpl::moveTo(const Point &p) ...@@ -188,23 +179,16 @@ void Atom::AtomImpl::moveTo(const Point &p)
mLocation = p; mLocation = p;
} }
const Compound &Atom::AtomImpl::comp() const const Compound *Atom::AtomImpl::compound() const
{ {
if (mCompound == nullptr) if (mCompound == nullptr)
{ {
std::string compID; std::string compID = get_property("label_comp_id");
cif::tie(compID) = mRow.get("label_comp_id");
mCompound = CompoundFactory::instance().create(compID); mCompound = CompoundFactory::instance().create(compID);
if (cif::VERBOSE > 0 and mCompound == nullptr)
std::cerr << "Compound not found: '" << compID << '\'' << std::endl;
} }
if (mCompound == nullptr) return mCompound;
throw std::runtime_error("no compound");
return *mCompound;
} }
const std::string Atom::AtomImpl::get_property(const std::string_view name) const const std::string Atom::AtomImpl::get_property(const std::string_view name) const
...@@ -281,6 +265,21 @@ std::string Atom::pdbID() const ...@@ -281,6 +265,21 @@ std::string Atom::pdbID() const
get_property<std::string>("pdbx_PDB_ins_code"); get_property<std::string>("pdbx_PDB_ins_code");
} }
const Compound &Atom::compound() const
{
auto result = impl().compound();
if (result == nullptr)
{
if (cif::VERBOSE > 0)
std::cerr << "Compound not found: '" << get_property<std::string>("label_comp_id") << '\'' << std::endl;
throw std::runtime_error("no compound");
}
return *result;
}
int Atom::charge() const int Atom::charge() const
{ {
return impl().charge(); return impl().charge();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment