Simpatico  v1.10
simp/species/Species.h
1 #ifndef SIMP_SPECIES_H
2 #define SIMP_SPECIES_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/param/ParamComposite.h> // base class
12 #include <util/containers/DArray.h> // member template
13 #include <util/containers/FSArray.h> // member template
14 #include <simp/species/SpeciesGroup.h> // member template parameter
15 
16 namespace McMd {
17  class SpeciesMutator;
18 }
19 
20 namespace Simp
21 {
22 
23  using namespace Util;
24 
25 
71  class Species : public ParamComposite
72  {
73 
74  public:
75 
76  #ifdef SIMP_BOND
77  static const int MaxBondPerAtom = 4;
79 
82 
85  #endif
86 
87  #ifdef SIMP_ANGLE
88  static const int MaxAnglePerAtom = 18;
90 
93 
96  #endif
97 
98  #ifdef SIMP_DIHEDRAL
99  static const int MaxDihedralPerAtom = 72;
101 
104 
107  #endif
108 
112  Species();
113 
117  virtual ~Species();
118 
120 
121 
127  void setId(int id);
128 
139  virtual void readParameters(std::istream &in);
140 
146  virtual void loadParameters(Serializable::IArchive &ar);
147 
153  void readStructure(std::istream& in);
154 
156 
158 
164  virtual void save(Serializable::OArchive &ar);
165 
172  void writeStructure(std::ostream& out,
173  std::string indent = std::string());
174 
183  bool matchStructure(std::istream& in);
184 
186 
188 
192  int nAtom() const;
193 
199  int atomTypeId(int iAtom) const;
200 
201  #ifdef SIMP_BOND
202 
205  int nBond() const;
206 
212  const SpeciesBond& speciesBond(int iBond) const;
213 
219  const AtomBondIdArray& atomBondIds(int atomId) const;
220  #endif
221 
222  #ifdef SIMP_ANGLE
223 
226  int nAngle() const;
227 
233  const SpeciesAngle& speciesAngle(int iAngle) const;
234 
240  const AtomAngleIdArray& atomAngleIds(int atomId) const;
241  #endif
242 
243  #ifdef SIMP_DIHEDRAL
244 
247  int nDihedral() const;
248 
254  const SpeciesDihedral& speciesDihedral(int iDihedral) const;
255 
261  const AtomDihedralIdArray& atomDihedralIds(int atomId) const;
262  #endif
263 
265 
267 
271  bool isMutable() const;
272 
277 
279 
281 
285  int id() const;
286 
290  int capacity() const;
291 
295  bool isValid() const;
296 
298 
299  protected:
300 
301  // Static constant
302 
304  static const int NullIndex = -1;
305 
306  // Non-static protected variables
307 
308  // These variables are protected, rather than private, so that they can
309  // be read and written by the (read|write)Param() functions of subclasses.
310 
312  int id_;
313 
316 
320  int nAtom_;
321 
329 
330  #ifdef SIMP_BOND
331 
334  int nBond_;
335 
343  #endif
344 
345  #ifdef SIMP_ANGLE
346 
349  int nAngle_;
350 
358  #endif
359 
360  #ifdef SIMP_DIHEDRAL
361 
365 
374  #endif
375 
376  // Methods
377 
394  virtual void readSpeciesParam(std::istream &in);
395 
406  virtual void loadSpeciesParam(Serializable::IArchive &ar);
407 
418  void allocate();
419 
425  void allocateAtoms();
426 
433  void setAtomType(int atomId, int atomType);
434 
435  #ifdef SIMP_BOND
436 
441  void allocateBonds();
442 
454  void makeBond(int bondId, int atomId1, int atomId2, int bondType);
455  #endif
456 
457  #ifdef SIMP_ANGLE
458 
463  void allocateAngles();
464 
477  void makeAngle(int angleId, int atomId1, int atomId2, int atomId3,
478  int angleType);
479  #endif
480 
481  #ifdef SIMP_DIHEDRAL
482 
485  void allocateDihedrals();
486 
500  void makeDihedral(int dihedralId, int atomId1, int atomId2, int atomId3,
501  int atomId4, int dihedralType);
502  #endif
503 
511 
527  void setMutatorPtr(McMd::SpeciesMutator* mutatorPtr);
528 
529  private:
530 
531  #ifdef SIMP_BOND
532 
539  DArray<AtomBondIdArray> atomBondIdArrays_;
540  #endif
541 
542  #ifdef SIMP_ANGLE
543 
550  DArray<AtomAngleIdArray> atomAngleIdArrays_;
551  #endif
552 
553  #ifdef SIMP_DIHEDRAL
554 
561  DArray<AtomDihedralIdArray> atomDihedralIdArrays_;
562  #endif
563 
570  McMd::SpeciesMutator* mutatorPtr_;
571 
572  };
573 
574  // Inline member function definitions
575 
576  /*
577  * Get integer id for this Species.
578  */
579  inline int Species::id() const
580  { return id_; }
581 
582  /*
583  * Get maximum number of molecules for this Species.
584  */
585  inline int Species::capacity() const
586  { return moleculeCapacity_; }
587 
588  /*
589  * Get number of Atoms per molecule.
590  */
591  inline int Species::nAtom() const
592  { return nAtom_; }
593 
594  /*
595  * Get type index for atom number iAtom.
596  */
597  inline int Species::atomTypeId(int iAtom) const
598  { return atomTypeIds_[iAtom]; }
599 
600  #ifdef SIMP_BOND
601  /*
602  * Get number of Bonds per molecule
603  */
604  inline int Species::nBond() const
605  { return nBond_; }
606 
607  /*
608  * Get a specific SpeciesBond object by local index.
609  */
610  inline
612  { return speciesBonds_[iBond]; }
613 
614  /*
615  * Get array of ids for bonds that contain one atom.
616  */
617  inline
619  { return atomBondIdArrays_[atomId]; }
620  #endif
621 
622  #ifdef SIMP_ANGLE
623  /*
624  * Get number of angles per molecule.
625  */
626  inline int Species::nAngle() const
627  { return nAngle_; }
628 
629  /*
630  * Get a specific SpeciesAngle object by local index.
631  */
632  inline
634  { return speciesAngles_[iAngle]; }
635 
636  /*
637  * Get array of ids for angles that contain one Atom.
638  */
639  inline
641  { return atomAngleIdArrays_[atomId]; }
642  #endif
643 
644  #ifdef SIMP_DIHEDRAL
645  /*
646  * Get number of dihedrals per molecule
647  */
648  inline int Species::nDihedral() const
649  { return nDihedral_; }
650 
651  /*
652  * Get a specific SpeciesDihedral object by local index.
653  */
654  inline
656  const
657  { return speciesDihedrals_[iDihedral]; }
658 
659  /*
660  * Get array of ids for dihedrals that contain one Atom.
661  */
662  inline
664  const
665  { return atomDihedralIdArrays_[atomId]; }
666  #endif
667 
668  /*
669  * Is this a mutable species?
670  */
671  inline bool Species::isMutable() const
672  { return (mutatorPtr_ != 0); }
673 
674  /*
675  * Get associated mutator object.
676  */
678  {
679  assert(mutatorPtr_);
680  return *mutatorPtr_;
681  }
682 
683 }
684 #endif
void setAtomType(int atomId, int atomType)
Set the type for one atom in a generic molecule of this Species.
SpeciesGroup< 3 > SpeciesAngle
A SpeciesAngle has local atom ids and a type id for one angle.
const AtomDihedralIdArray & atomDihedralIds(int atomId) const
Get array of ids for dihedrals that contain one Atom.
const SpeciesDihedral & speciesDihedral(int iDihedral) const
Get a specific SpeciesDihedral object, by local angle index.
A Group of covalently interacting atoms within any molecule of one Species.
Definition: SpeciesGroup.h:20
static const int MaxBondPerAtom
Maximum number of bonds that can be connected to one atom.
static const int MaxDihedralPerAtom
Maximum number of dihedral groups that can contain one atom.
int nAtom() const
Get number of atoms per molecule for this Species.
int moleculeCapacity_
Number of molecules associated with the species.
DArray< SpeciesDihedral > speciesDihedrals_
Array of SpeciesDihedrals, indexed by local dihedral id.
SpeciesGroup< 4 > SpeciesDihedral
A SpeciesDihedral has local atom ids and a type id for one dihedral.
void setMutatorPtr(McMd::SpeciesMutator *mutatorPtr)
Set pointer to associated McMd::SpeciesMutator for a mutable species.
void writeStructure(std::ostream &out, std::string indent=std::string())
Write molecular structure in config/topology file format.
static const int MaxAnglePerAtom
Maximum number of angles groups that can contain one atom.
DArray< SpeciesBond > speciesBonds_
Array of SpeciesBonds for all bonds, indexed by local bond id.
FSArray< int, MaxAnglePerAtom > AtomAngleIdArray
An array of local angle ids for all angles containing one atom.
virtual void readSpeciesParam(std::istream &in)
Define chemical structure for this Species.
virtual ~Species()
Destructor.
void allocateAtoms()
Allocate and initialize array of atom type Ids.
Classes used by all simpatico molecular simulations.
Mix-in class for mutable subclasses of Species.
void allocateDihedrals()
Allocate arrays associated with dihedrals.
static const int NullIndex
Null (unknown) value for any non-negative index.
int nAtom_
Number of atoms per molecule.
Saving / output archive for binary ostream.
DArray< int > atomTypeIds_
Array of atom type Ids, indexed by local atom id.
const SpeciesBond & speciesBond(int iBond) const
Get a specific SpeciesBond object, by local bond index.
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:37
int nDihedral() const
Get number of dihedrals per molecule for this Species.
Species()
Constructor.
const AtomAngleIdArray & atomAngleIds(int atomId) const
Get array of ids for angles that contain one Atom.
DArray< SpeciesAngle > speciesAngles_
Array of SpeciesAngles for all angles, indexed by local angle id.
void makeDihedral(int dihedralId, int atomId1, int atomId2, int atomId3, int atomId4, int dihedralType)
Add a dihedral to the chemical structure of a generic molecule.
FSArray< int, MaxDihedralPerAtom > AtomDihedralIdArray
An array of local angle ids for all dihedrals containing one atom.
Utility classes for scientific computation.
Definition: accumulators.mod:1
SpeciesGroup< 2 > SpeciesBond
A SpeciesBond has the local atom ids and a type id for one bond.
const SpeciesAngle & speciesAngle(int iAngle) const
Get a specific SpeciesAngle object, by local angle index.
bool matchStructure(std::istream &in)
Read structure, return true iff it matches existing structure.
int nDihedral_
Number of dihedrals per molecule.
int atomTypeId(int iAtom) const
Get atom type index for a specific atom, by local atom index.
int nAngle_
Number of angles per molecule.
bool isValid() const
Return true if Species is valid, or throw an Exception.
virtual void readParameters(std::istream &in)
Read parameters and initialize structure for this species.
void makeBond(int bondId, int atomId1, int atomId2, int bondType)
Add a bond to the chemical structure of a generic molecule.
void setId(int id)
Set integer id for this Species.
void allocateBonds()
Allocate arrays associated with Bonds.
int id_
Integer index for this Species.
int id() const
Get integer id of this Species.
Saving archive for binary istream.
void makeAngle(int angleId, int atomId1, int atomId2, int atomId3, int angleType)
Add an angle to the chemical structure of a generic molecule.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void readStructure(std::istream &in)
Read structure from config/topology file format.
bool isMutable() const
Is this a mutable Species?
const AtomBondIdArray & atomBondIds(int atomId) const
Get array of ids for Bonds that contain one Atom.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
virtual void loadSpeciesParam(Serializable::IArchive &ar)
Define chemical structure for this Species.
int capacity() const
Maximum allowed number of molecules for this Species.
void allocate()
Allocate chemical structure arrays.
An object that can read multiple parameters from file.
McMd::SpeciesMutator & mutator()
Return the species mutator object by reference.
A Species represents a set of chemically similar molecules.
int nBond() const
Get number of bonds per molecule for this Species.
int nAngle() const
Get number of angles per molecule for this Species.
std::string indent() const
Return indent string for this object (string of spaces).
int nBond_
Number of bonds per molecule.
void initializeAtomGroupIdArrays()
Initialize all atom groupId arrays (point from atoms to groups).
FSArray< int, MaxBondPerAtom > AtomBondIdArray
An array of local integer bond ids for all bonds containing one atom.
void allocateAngles()
Allocate arrays associated with angles.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.