From 20efccaf12aaa4122d28516f87934f396714ff8c Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Mon, 31 May 2021 17:42:27 +0200 Subject: [PATCH 1/2] Add int_ptr() function to enable unique identification of objects through their address - useful in python where the wrapped object has a different address --- ObjCryst/ObjCryst/Molecule.cpp | 17 +++++++++++++++++ ObjCryst/ObjCryst/Molecule.h | 13 ++++++++++++- ObjCryst/RefinableObj/RefinableObj.cpp | 1 + ObjCryst/RefinableObj/RefinableObj.h | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ObjCryst/ObjCryst/Molecule.cpp b/ObjCryst/ObjCryst/Molecule.cpp index 99098728..4c812992 100644 --- a/ObjCryst/ObjCryst/Molecule.cpp +++ b/ObjCryst/ObjCryst/Molecule.cpp @@ -354,6 +354,8 @@ bool MolAtom::IsNonFlipAtom() const return mIsNonFlipAtom; } +size_t MolAtom::int_ptr() const {return (size_t)this;} + #ifdef __WX__CRYST__ WXCrystObjBasic* MolAtom::WXCreate(wxWindow* parent) { @@ -633,6 +635,9 @@ void MolBond::SetFreeTorsion(const bool isFreeTorsion) mIsFreeTorsion=isFreeTorsion; mpMol->GetBondListClock().Click(); } + +size_t MolBond::int_ptr() const {return (size_t)this;} + #ifdef __WX__CRYST__ WXCrystObjBasic* MolBond::WXCreate(wxWindow* parent) { @@ -940,6 +945,9 @@ void MolBondAngle::SetAtom3(MolAtom& at){mvpAtom[2]=&at;} std::size_t MolBondAngle::size() const {return mvpAtom.size();} vector::const_iterator MolBondAngle::begin() const {return mvpAtom.begin();} vector::const_iterator MolBondAngle::end() const {return mvpAtom.end();} + +size_t MolBondAngle::int_ptr() const {return (size_t)this;} + #ifdef __WX__CRYST__ WXCrystObjBasic* MolBondAngle::WXCreate(wxWindow* parent) { @@ -1300,6 +1308,9 @@ MolAtom& MolDihedralAngle::GetAtom4(){return *(mvpAtom[3]);} std::size_t MolDihedralAngle::size() const {return mvpAtom.size();} vector::const_iterator MolDihedralAngle::begin() const {return mvpAtom.begin();} vector::const_iterator MolDihedralAngle::end() const {return mvpAtom.end();} + +size_t MolDihedralAngle::int_ptr() const {return (size_t)this;} + #ifdef __WX__CRYST__ WXCrystObjBasic* MolDihedralAngle::WXCreate(wxWindow* parent) { @@ -1324,6 +1335,9 @@ string RigidGroup::GetName()const for(;at!=this->end();++at) name+=", "+(*at)->GetName(); return name; } + +size_t RigidGroup::int_ptr() const {return (size_t)this;} + //###################################################################### // // MolRing @@ -1337,6 +1351,9 @@ const std::list& MolRing::GetAtomList()const std::list& MolRing::GetAtomList() {return mvpAtom;} + +size_t MolRing::int_ptr() const {return (size_t)this;} + //###################################################################### // // Quaternion diff --git a/ObjCryst/ObjCryst/Molecule.h b/ObjCryst/ObjCryst/Molecule.h index 37bb143a..badf3e8c 100644 --- a/ObjCryst/ObjCryst/Molecule.h +++ b/ObjCryst/ObjCryst/Molecule.h @@ -117,6 +117,8 @@ class MolAtom void SetNonFlipAtom(const bool nonflip); /// Can this atom be flipped (return=false) or should its absolute configuration be kept (return=true) bool IsNonFlipAtom() const; + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; private: /// Name for this atom string mName; @@ -229,7 +231,8 @@ class MolBond:public Restraint void SetBondOrder(const REAL length); bool IsFreeTorsion()const; void SetFreeTorsion(const bool isInRing); - + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; private: pair mAtomPair; REAL mLength0,mDelta,mSigma; @@ -320,6 +323,8 @@ class MolBondAngle:public Restraint std::size_t size() const; vector::const_iterator begin() const; vector::const_iterator end() const; + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; private: /// The vector of the 3 atoms involved in the bond angle. vector mvpAtom; @@ -415,6 +420,8 @@ class MolDihedralAngle:public Restraint std::size_t size() const; vector::const_iterator begin() const; vector::const_iterator end() const; + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; private: /// The vector of the 4 atoms involved in the bond angle. vector mvpAtom; @@ -454,6 +461,8 @@ class MolRing MolRing(); const std::list& GetAtomList()const; std::list& GetAtomList(); + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; private: std::list mvpAtom; }; @@ -529,6 +538,8 @@ class RigidGroup:public std::set /// Temporary list of the atoms indices in the molecule, used during optimization /// This is created in Molecule::BeginOptimization() mutable std::set mvIdx; + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; }; /** Abstract base Stretch Mode for Molecule objects diff --git a/ObjCryst/RefinableObj/RefinableObj.cpp b/ObjCryst/RefinableObj/RefinableObj.cpp index 093de7a4..52ce27c3 100644 --- a/ObjCryst/RefinableObj/RefinableObj.cpp +++ b/ObjCryst/RefinableObj/RefinableObj.cpp @@ -1981,6 +1981,7 @@ void RefinableObj::TagNewBestConfig()const } const RefinableObjClock& RefinableObj::GetClockMaster()const{return mClockMaster;} +size_t RefinableObj::int_ptr() const {return (size_t)this;} void RefinableObj::UpdateDisplay()const { diff --git a/ObjCryst/RefinableObj/RefinableObj.h b/ObjCryst/RefinableObj/RefinableObj.h index 0eaf8673..d6c72dd5 100644 --- a/ObjCryst/RefinableObj/RefinableObj.h +++ b/ObjCryst/RefinableObj/RefinableObj.h @@ -1238,6 +1238,8 @@ class RefinableObj virtual void TagNewBestConfig()const; /// This clocks records _any_ change in the object. See refinableObj::mClockMaster const RefinableObjClock& GetClockMaster()const; + /// Access to the integer address of this object, for unique identification from python + size_t int_ptr() const; protected: /// Find a refinable parameter with a given name long FindPar(const string &name) const; From e7bb0632669614597e8f300af8a2289beb1313af Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Sat, 12 Jun 2021 09:35:27 +0200 Subject: [PATCH 2/2] CreateCrystalFromCIF: throw exception if no crystal structure is found --- ObjCryst/ObjCryst/CIF.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ObjCryst/ObjCryst/CIF.cpp b/ObjCryst/ObjCryst/CIF.cpp index 5b2d6387..68750337 100644 --- a/ObjCryst/ObjCryst/CIF.cpp +++ b/ObjCryst/ObjCryst/CIF.cpp @@ -1014,7 +1014,8 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX bool import_multiple = true; if(pCryst!=NULL) import_multiple = false; - + bool crystal_found = false; + for(map::iterator pos=cif.mvData.begin();pos!=cif.mvData.end();++pos) if(pos->second.mvLatticePar.size()==6) { @@ -1102,6 +1103,7 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX else pCryst->Init(pos->second.mvLatticePar[0],pos->second.mvLatticePar[1],pos->second.mvLatticePar[2], pos->second.mvLatticePar[3],pos->second.mvLatticePar[4],pos->second.mvLatticePar[5],spg, ""); + crystal_found = true; if( (pos->second.mSpacegroupSymbolHall=="") &&(pos->second.mvSymmetry_equiv_pos_as_xyz.size()>0) &&(pos->second.mSpacegroupHermannMauguin!="") @@ -1290,6 +1292,7 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX if(pCryst->GetName()=="") pCryst->SetName(pCryst->GetFormula()); if(!import_multiple) return pCryst; } + if(!crystal_found) throw ObjCrystException("CreateCrystalFromCIF: no structure found"); return pCryst; }