diff --git include/openbabel/atom.h include/openbabel/atom.h index 74553914..0f35922e 100644 --- include/openbabel/atom.h +++ include/openbabel/atom.h @@ -284,7 +284,7 @@ namespace OpenBabel //! \return the residue which contains this atom, or NULL if none exists OBResidue *GetResidue(bool perception); //! \return the molecule which contains this atom, or NULL if none exists - OBMol *GetParent() {return((OBMol*)_parent);} + OBMol *GetParent() const {return((OBMol*)_parent);} //! Create a vector for a new bond from this atom, with length given by the supplied parameter //! \return success or failure bool GetNewBondVector(vector3 &v,double length); @@ -486,7 +486,7 @@ namespace OpenBabel //! \return Is this atom chiral? bool IsChiral(); //! \return Is the atom part of a periodic unit cell? - bool IsPeriodic(); + bool IsPeriodic() const; //! \return Is this atom an axial atom in a ring bool IsAxial(); //! \deprecated diff --git include/openbabel/bond.h include/openbabel/bond.h index 838998df..9a168ada 100644 --- include/openbabel/bond.h +++ include/openbabel/bond.h @@ -222,14 +222,12 @@ namespace OpenBabel return((ptr != _bgn)? _bgn : _end); } //! \return The enclosing OBMol for this bond, or NULL if none is defined. - OBMol *GetParent() {return(_parent);} + OBMol *GetParent() const {return(_parent);} //! \return The expected "equilibrium" length based on the covalent radii and bond order /** Length is given in Angstroms **/ double GetEquibLength() const; //! \return The current length of this bond in Angstroms - //! \todo What is the effect of removing the "const" declaration? - //! \todo It appears the problem is that GetLength is const, but OBAtom::GetDistance is not because GetVector is not. - double GetLength(); + double GetLength() const; //! \return The index to the neighboring atom of @p ptr (i.e., the end if @p ptr is the start) /** \warning If @p ptr is not part of the bond, the beginning atom index will always be returned **/ @@ -261,7 +259,7 @@ namespace OpenBabel bool IsRotor(); /** \return Is the bond an amide link (i.e., between a carbonyl C and a N)? No distinction is made between primary, secondary, and tertiary amides. **/ - bool IsPeriodic(); + bool IsPeriodic() const; //! \return Is the bond within a periodic unit cell? bool IsAmide(); /** \return Is the bond a primary amide (i.e., between carbonyl C and a NH2)? diff --git include/openbabel/mol.h include/openbabel/mol.h index 94c603a0..6d2bbf1c 100644 --- include/openbabel/mol.h +++ include/openbabel/mol.h @@ -135,7 +135,7 @@ enum HydrogenType { AllHydrogen, PolarHydrogen, NonPolarHydrogen }; std::vector _internals; //!< Internal Coordinates (if applicable) unsigned short int _mod; //!< Number of nested calls to BeginModify() - bool HasFlag(int flag) { return((_flags & flag) ? true : false); } + bool HasFlag(int flag) const { return((_flags & flag) ? true : false); } void SetFlag(int flag) { _flags |= flag; } //! \name Internal Kekulization routines -- see kekulize.cpp and NewPerceiveKekuleBonds() @@ -632,7 +632,7 @@ enum HydrogenType { AllHydrogen, PolarHydrogen, NonPolarHydrogen }; //! Is this molecule chiral? bool IsChiral(); //! Is this molecule periodic? Should periodic boundary conditions be applied? - bool IsPeriodic() { return(HasFlag(OB_PERIODIC_MOL)); } + bool IsPeriodic() const { return(HasFlag(OB_PERIODIC_MOL)); } //! Are there any atoms in this molecule? bool Empty() { return(_natoms == 0); } //@} diff --git src/atom.cpp src/atom.cpp index f7e14a9a..b7a014ee 100644 --- src/atom.cpp +++ src/atom.cpp @@ -886,7 +886,7 @@ namespace OpenBabel return stereoFacade.HasTetrahedralStereo(_id); } - bool OBAtom::IsPeriodic() + bool OBAtom::IsPeriodic() const { OBMol *mol = (OBMol*) GetParent(); return mol->IsPeriodic(); diff --git src/bond.cpp src/bond.cpp index 0d537e9f..f116e272 100644 --- src/bond.cpp +++ src/bond.cpp @@ -203,7 +203,7 @@ namespace OpenBabel return (_bgn->GetHvyValence() > 1 && _end->GetHvyValence() > 1); } - bool OBBond::IsPeriodic() + bool OBBond::IsPeriodic() const { return ((OBMol*)GetParent())->IsPeriodic(); } @@ -746,10 +746,10 @@ namespace OpenBabel return(length); } - double OBBond::GetLength() + double OBBond::GetLength() const { double d2; - OBAtom *begin, *end; + const OBAtom *begin, *end; begin = GetBeginAtom(); end = GetEndAtom(); @@ -762,7 +762,8 @@ namespace OpenBabel } else { - return(begin->GetDistance(end)); + OBUnitCell *box = (OBUnitCell*)GetParent()->GetData(OBGenericDataType::UnitCell); + return (box->MinimumImageCartesian(begin->GetVector() - end->GetVector())).length(); } }