/** \file molecule.hpp * * Class definitions of atom and molecule, element and periodentafel */ #ifndef MOLECULES_HPP_ #define MOLECULES_HPP_ /*********************************************** includes ***********************************/ #ifdef HAVE_CONFIG_H #include #endif //// STL headers #include #include #include #include #include #include #include #include "types.hpp" #include "graph.hpp" #include "CodePatterns/Observer.hpp" #include "CodePatterns/ObservedIterator.hpp" #include "CodePatterns/Cacheable.hpp" #include "Helpers/defs.hpp" #include "Formula.hpp" #include "AtomSet.hpp" #include "Descriptors/MoleculeDescriptor_impl.hpp" /****************************************** forward declarations *****************************/ class atom; class bond; class BondedParticle; class BondGraph; class DepthFirstSearchAnalysis; class element; class ForceMatrix; class LinkedCell; class molecule; class MoleculeLeafClass; class MoleculeListClass; class periodentafel; class RealSpaceMatrix; class Vector; class Shape; /******************************** Some definitions for easier reading **********************************/ #define MoleculeList list #define MoleculeListTest pair /************************************* Class definitions ****************************************/ /** The complete molecule. * Class incorporates number of types */ class molecule : public Observable { friend molecule *NewMolecule(); friend void DeleteMolecule(molecule *); public: typedef ATOMSET(std::list) atomSet; typedef ATOMSET(std::vector) atomVector; typedef std::set atomIdSet; typedef ObservedIterator iterator; typedef atomSet::const_iterator const_iterator; const periodentafel * const elemente; //!< periodic table with each element // old deprecated atom handling //atom *start; //!< start of atom list //atom *end; //!< end of atom list //bond *first; //!< start of bond list //bond *last; //!< end of bond list int MDSteps; //!< The number of MD steps in Trajectories mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis() bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules //Vector Center; //!< Center of molecule in a global box int IndexNr; //!< index of molecule in a MoleculeListClass char name[MAXSTRINGSIZE]; //!< arbitrary name private: Formula formula; Cacheable AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms() Cacheable BondCount; //!< number of atoms, brought up-to-date by doCountBonds() moleculeId_t id; atomSet atoms; // insert(atom * const key); bool containsAtom(atom* key); private: friend void atom::removeFromMolecule(); /** Erase an atom from the list. * \note This should only be called by atom::removeFromMolecule(), * otherwise it is not assured that the atom knows about it. * * @param loc locator to atom in list * @return iterator to just after removed item (compliant with standard) */ const_iterator erase(const_iterator loc); /** Erase an atom from the list. * \note This should only be called by atom::removeFromMolecule(), * otherwise it is not assured that the atom knows about it. * * @param *key key to atom in list * @return iterator to just after removed item (compliant with standard) */ const_iterator erase(atom * key); public: /// remove atoms from molecule. bool AddAtom(atom *pointer); bool RemoveAtom(atom *pointer); bool UnlinkAtom(atom *pointer); bool CleanupMolecule(); void removeAtomsinMolecule(); /// Add/remove atoms to/from molecule. atom * AddCopyAtom(atom *pointer); bool AddXYZFile(string filename); bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem); bond * AddBond(atom *first, atom *second, int degree = 1); bool RemoveBond(bond *pointer); bool RemoveBonds(atom *BondPartner); bool hasBondStructure() const; /// Find atoms. atom * FindAtom(int Nr) const; atom * AskAtom(string text); /// Count and change present atoms' coordination. bool CenterInBox(); bool BoundInBox(); void CenterEdge(Vector *max); void CenterOrigin(); void CenterPeriodic(); void CenterAtVector(Vector *newcenter); void Translate(const Vector *x); void TranslatePeriodically(const Vector *trans); void Mirror(const Vector *x); void Align(Vector *n); void Scale(const double ** const factor); void DeterminePeriodicCenter(Vector ¢er); Vector * DetermineCenterOfGravity() const; Vector * DetermineCenterOfAll() const; Vector * DetermineCenterOfBox() const; void SetNameFromFilename(const char *filename); void SetBoxDimension(Vector *dim); bool ScanForPeriodicCorrection(); double VolumeOfConvexEnvelope(bool IsAngstroem); RealSpaceMatrix getInertiaTensor() const; void RotateToPrincipalAxisSystem(Vector &Axis); bool CheckBounds(const Vector *x) const; void GetAlignvector(struct lsq_params * par) const; /// Initialising routines in fragmentation void OutputBondsList() const; bond * CopyBond(atom *left, atom *right, bond *CopyBond); molecule *CopyMolecule() const; molecule* CopyMoleculeFromSubRegion(const Shape&) const; /// Fragment molecule by two different approaches: int FragmentMolecule(int Order, std::string &prefix, DepthFirstSearchAnalysis &DFS); bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, std::string path = ""); bool StoreBondsToFile(std::string filename, std::string path = ""); bool StoreAdjacencyToFile(std::string filename, std::string path = ""); bool ParseOrderAtSiteFromFile(std::string &path); bool StoreOrderAtSiteFile(std::string &path); bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex); bool CreateMappingLabelsToConfigSequence(int *&SortIndex); bool CreateFatherLookupTable(atom **&LookupTable, int count = 0); /// -# BOSSANOVA void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack); int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet); molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem); void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector &BondsSet, int SetDimension, int SubOrder); int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList); int GuesstimateFragmentCount(int order); // Recognize doubly appearing molecules in a list of them int * GetFatherSonAtomicMap(molecule *OtherMolecule); bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false); bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount); // Output routines. bool Output(std::ostream * const output) const; bool OutputTrajectories(ofstream * const output) const; void OutputListOfBonds() const; bool OutputXYZ(ofstream * const output) const; bool OutputTrajectoriesXYZ(ofstream * const output); bool Checkout(ofstream * const output) const; // Manipulation routines void flipActiveFlag(); private: int last_atom; //!< number given to last atom }; molecule *NewMolecule(); void DeleteMolecule(molecule* mol); /** A list of \a molecule classes. */ class MoleculeListClass : public Observable { public: MoleculeList ListOfMolecules; //!< List of the contained molecules int MaxIndex; MoleculeListClass(World *world); ~MoleculeListClass(); bool AddHydrogenCorrection(std::string &path); bool StoreForcesFile(std::string &path, int *SortIndex); void insert(molecule *mol); void erase(molecule *mol); molecule * ReturnIndex(int index); bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex); int NumberOfActiveMolecules(); void Enumerate(ostream *out); void Output(ofstream *out); int CountAllAtoms() const; // Methods moved here from the menus // TODO: more refactoring needed on these methods void createNewMolecule(periodentafel *periode); void loadFromXYZ(periodentafel *periode); void setMoleculeFilename(); void parseXYZIntoMolecule(); void eraseMolecule(); private: World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor }; /** A leaf for a tree of \a molecule class * Wraps molecules in a tree structure */ class MoleculeLeafClass { public: molecule *Leaf; //!< molecule of this leaf //MoleculeLeafClass *UpLeaf; //!< Leaf one level up //MoleculeLeafClass *DownLeaf; //!< First leaf one level down MoleculeLeafClass *previous; //!< Previous leaf on this level MoleculeLeafClass *next; //!< Next leaf on this level //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous); MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf); ~MoleculeLeafClass(); bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous); bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter); bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false); void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph); int Count() const; }; #endif /*MOLECULES_HPP_*/