/** \file molecule.hpp * * Class definitions of atom and molecule, element and periodentafel */ #ifndef MOLECULES_HPP_ #define MOLECULES_HPP_ using namespace std; /*********************************************** includes ***********************************/ // GSL headers #include #include #include #include #include #include #include //// STL headers #include #include #include #include #include #include "graph.hpp" #include "stackclass.hpp" #include "tesselation.hpp" /****************************************** forward declarations *****************************/ class atom; class bond; class BondedParticle; class BondGraph; class element; class ForceMatrix; class LinkedCell; class molecule; class MoleculeLeafClass; class MoleculeListClass; class periodentafel; class Vector; /******************************** Some definitions for easier reading **********************************/ #define MoleculeList list #define MoleculeListTest pair #define DistancePair pair < double, atom* > #define DistanceMap multimap < double, atom* > #define DistanceTestPair pair < DistanceMap::iterator, bool> /************************************* Class definitions ****************************************/ /** Structure to contain parameters needed for evaluation of constraint potential. */ struct EvaluatePotential { int startstep; //!< start configuration (MDStep in atom::trajectory) int endstep; //!< end configuration (MDStep in atom::trajectory) atom **PermutationMap; //!< gives target ptr for each atom, array of size molecule::AtomCount (this is "x" in \f$ V^{con}(x) \f$ ) DistanceMap **DistanceList; //!< distance list of each atom to each atom DistanceMap::iterator *StepList; //!< iterator to ascend through NearestNeighbours \a **DistanceList int *DoubleList; //!< count of which sources want to move to this target, basically the injective measure (>1 -> not injective) DistanceMap::iterator *DistanceIterators; //!< marks which was the last picked target as injective candidate with smallest distance bool IsAngstroem; //!< whether coordinates are in angstroem (true) or bohrradius (false) double *PenaltyConstants; //!< penalty constant in front of each term }; #define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented enum thermostats { None, Woodcock, Gaussian, Langevin, Berendsen, NoseHoover }; //!< Thermostat names for output /** The complete molecule. * Class incorporates number of types */ class molecule : public PointCloud { public: double cell_size[6];//!< cell size const periodentafel * const elemente; //!< periodic table with each element 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 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms() int BondCount; //!< number of atoms, brought up-to-date by CountBonds() int ElementCount; //!< how many unique elements are therein int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not 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() double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules Vector Center; //!< Center of molecule in a global box char name[MAXSTRINGSIZE]; //!< arbitrary name int IndexNr; //!< index of molecule in a MoleculeListClass molecule(const periodentafel * const teil); virtual ~molecule(); // re-definition of virtual functions from PointCloud Vector *GetCenter(ofstream *out) const ; TesselPoint *GetPoint() const ; TesselPoint *GetTerminalPoint() const ; void GoToNext() const ; void GoToPrevious() const ; void GoToFirst() const ; void GoToLast() const ; bool IsEmpty() const ; bool IsEnd() const ; // templates for allowing global manipulation of all vectors template void ActOnAllVectors( res (Vector::*f)() ) const; template void ActOnAllVectors( res (Vector::*f)() const) const; template void ActOnAllVectors( res (Vector::*f)(T), T t ) const; template void ActOnAllVectors( res (Vector::*f)(T) const, T t ) const; template void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const; template void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const; template void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const; template void ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const; // templates for allowing global manipulation of molecule with each atom as single argument template void ActWithEachAtom( res (molecule::*f)(atom *) ) const; template void ActWithEachAtom( res (molecule::*f)(atom *) const) const; // templates for allowing global copying of molecule with each atom as single argument template void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const; template void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const; // templates for allowing global manipulation of all atoms template void ActOnAllAtoms( res (typ::*f)() ) const; template void ActOnAllAtoms( res (typ::*f)() const) const; template void ActOnAllAtoms( res (typ::*f)(T), T t ) const; template void ActOnAllAtoms( res (typ::*f)(T) const, T t ) const; template void ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const; template void ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const; template void ActOnAllAtoms( res (typ::*f)(T, U, V), T t, U u, V v) const; template void ActOnAllAtoms( res (typ::*f)(T, U, V) const, T t, U u, V v) const; template void ActOnAllAtoms( res (typ::*f)(T, U, V, W), T t, U u, V v, W w) const; template void ActOnAllAtoms( res (typ::*f)(T, U, V, W) const, T t, U u, V v, W w) const; // templates for allowing conditional global copying of molecule with each atom as single argument template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () const ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) (T), T t ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) (T) const, T t ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const; template void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const; // templates for allowing global manipulation of an array with one entry per atom void SetIndexedArrayForEachAtomTo ( atom **array, int ParticleInfo::* index) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::* index, void (*Setor)(T *, T *)) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::* index, void (*Setor)(T *, T *), T t) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::* index, void (*Setor)(T *, T *), T *t) const; template void SetIndexedArrayForEachAtomTo ( T *array, int element::* index, void (*Setor)(T *, T *)) const; template void SetIndexedArrayForEachAtomTo ( T *array, int element::* index, void (*Setor)(T *, T *), T t) const; template void SetIndexedArrayForEachAtomTo ( T *array, int element::* index, void (*Setor)(T *, T *), T *t) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const; template void SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const; // templates for allowing global manipulation of each atom by entries in an array template void SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const; template void SetAtomValueToValue ( T value, T typ::*ptr ) const; template res SumPerAtom(res (typ::*f)() ) const; template res SumPerAtom(res (typ::*f)() const ) const; template res SumPerAtom(res (typ::*f)(T) , T t ) const; template res SumPerAtom(res (typ::*f)(T) const, T t ) const; /// remove atoms from molecule. bool AddAtom(atom *pointer); bool RemoveAtom(atom *pointer); bool UnlinkAtom(atom *pointer); bool CleanupMolecule(); /// Add/remove atoms to/from molecule. atom * AddCopyAtom(atom *pointer); bool AddXYZFile(string filename); bool AddHydrogenReplacementAtom(ofstream *out, 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); /// Find atoms. atom * FindAtom(int Nr) const; atom * AskAtom(string text); /// Count and change present atoms' coordination. void CountAtoms(ofstream *out); void CountElements(); void CalculateOrbitals(class config &configuration); bool CenterInBox(ofstream *out); bool BoundInBox(ofstream *out); void CenterEdge(ofstream *out, Vector *max); void CenterOrigin(ofstream *out); void CenterPeriodic(ofstream *out); void CenterAtVector(ofstream *out, 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(ofstream *out); Vector * DetermineCenterOfAll(ofstream *out) const; void SetNameFromFilename(const char *filename); void SetBoxDimension(Vector *dim); void ScanForPeriodicCorrection(ofstream *out); bool VerletForceIntegration(ofstream *out, char *file, config &configuration); void Thermostats(config &configuration, double ActualTemp, int Thermostat); void PrincipalAxisSystem(ofstream *out, bool DoRotate); double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem); double ConstrainedPotential(ofstream *out, struct EvaluatePotential &Params); double MinimiseConstrainedPotential(ofstream *out, atom **&permutation, int startstep, int endstep, bool IsAngstroem); void EvaluateConstrainedForces(ofstream *out, int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force); bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration, bool MapByIdentity); bool CheckBounds(const Vector *x) const; void GetAlignvector(struct lsq_params * par) const; /// Initialising routines in fragmentation void CreateAdjacencyListFromDbondFile(ofstream *out, ifstream *output); void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem, void (BondGraph::*f)(BondedParticle * const , BondedParticle * const , double &, double &, bool), BondGraph *BG = NULL); int CorrectBondDegree(ofstream *out) const; void OutputBondsList(ofstream *out) const; void CyclicBondAnalysis() const; void OutputGraphInfoPerAtom(ofstream *out) const; void OutputGraphInfoPerBond(ofstream *out) const; // Graph analysis MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass *&BackEdgeStack) const; void CyclicStructureAnalysis(ofstream *out, class StackClass *BackEdgeStack, int *&MinimumRingSize) const; bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass *&ReferenceStack, class StackClass *&LocalStack) const; bond * FindNextUnused(atom *vertex) const; void SetNextComponentNumber(atom *vertex, int nr) const; void ResetAllBondsToUnused() const; int CountCyclicBonds(ofstream *out); bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment); string GetColor(enum Shading color) const; bond * CopyBond(atom *left, atom *right, bond *CopyBond); molecule *CopyMolecule(); molecule* CopyMoleculeFromSubRegion(const Vector offset, const double *parallelepiped) const; /// Fragment molecule by two different approaches: int FragmentMolecule(ofstream *out, int Order, config *configuration); bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL); bool StoreAdjacencyToFile(ofstream *out, char *path); bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms); bool ParseOrderAtSiteFromFile(ofstream *out, char *path); bool StoreOrderAtSiteFile(ofstream *out, char *path); bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex); bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex); void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem); /// -# BOSSANOVA void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize); int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet); bool BuildInducedSubgraph(ofstream *out, const molecule *Father); molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem); void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder); int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList); int GuesstimateFragmentCount(ofstream *out, int order); // Recognize doubly appearing molecules in a list of them int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold); int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule); // Output routines. bool Output(ofstream *out); bool OutputTrajectories(ofstream *out); void OutputListOfBonds(ofstream *out) const; bool OutputXYZ(ofstream *out) const; bool OutputTrajectoriesXYZ(ofstream *out); bool Checkout(ofstream *out) const; bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output); private: int last_atom; //!< number given to last atom mutable atom *InternalPointer; //!< internal pointer for PointCloud }; #include "molecule_template.hpp" /** A list of \a molecule classes. */ class MoleculeListClass { public: MoleculeList ListOfMolecules; //!< List of the contained molecules int MaxIndex; MoleculeListClass(); ~MoleculeListClass(); bool AddHydrogenCorrection(ofstream *out, char *path); bool StoreForcesFile(ofstream *out, char *path, int *SortIndex); void insert(molecule *mol); molecule * ReturnIndex(int index); bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex); int NumberOfActiveMolecules(); void Enumerate(ofstream *out); void Output(ofstream *out); void DissectMoleculeIntoConnectedSubgraphs(ofstream * const out, molecule * const mol, config * const configuration); // merging of molecules bool SimpleMerge(molecule *mol, molecule *srcmol); bool SimpleAdd(molecule *mol, molecule *srcmol); bool SimpleMultiMerge(molecule *mol, int *src, int N); bool SimpleMultiAdd(molecule *mol, int *src, int N); bool ScatterMerge(molecule *mol, int *src, int N); bool EmbedMerge(molecule *mol, molecule *srcmol); private: }; /** 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 FillBondStructureFromReference(ofstream *out, const molecule * const reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false); bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter); bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false); bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList); void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph); int Count() const; }; #endif /*MOLECULES_HPP_*/