Simpatico  v1.10
tools/chemistry/Species.h
1 #ifndef TOOLS_SPECIES_H
2 #define TOOLS_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 "Molecule.h"
12 #include <util/containers/DArray.h>
13 #include <util/containers/DSArray.h>
14 #include <util/containers/ArrayIterator.h>
15 
16 namespace Tools
17 {
18 
19  struct Atom;
20  using namespace Util;
21 
27  class Species {
28  public:
29 
31 
35  Species();
36 
40  ~Species();
41 
47  void setId(int id);
48 
55  void initialize(int nAtom, int capacity);
56 
62  void addAtom(Atom& atom);
63 
67  void clear();
68 
72  void begin(Iterator& iterator);
73 
79  Molecule& molecule(int i);
80 
84  int id() const;
85 
89  int nAtom() const;
90 
94  int size() const;
95 
99  int capacity() const;
100 
104  bool isValid() const;
105 
109  template <class Archive>
110  void serialize(Archive& ar, const unsigned int version);
111 
112  private:
113 
119  DArray<Atom*> atomPtrs_;
120 
128  DSArray<Molecule> molecules_;
129 
133  int id_;
134 
138  int nAtom_;
139 
143  int capacity_;
144 
148  void initialize();
149 
150  //friends:
151 
152  friend
153  std::istream& operator >> (std::istream& in, Species& species);
154 
155  friend
156  std::ostream& operator << (std::ostream& out, const Species& species);
157 
158  };
159 
167  std::istream& operator>>(std::istream& in, Species &species);
168 
178  std::ostream& operator << (std::ostream& out, const Species &species);
179 
180  // Inline function definitions
181 
182  /*
183  * Return a specific molecule.
184  */
185  inline Molecule& Species::molecule(int i)
186  { return molecules_[i]; }
187 
188  /*
189  * Return integer id for this species.
190  */
191  inline int Species::id() const
192  { return id_; }
193 
194  /*
195  * Return the number of atoms per molecule.
196  */
197  inline int Species::nAtom() const
198  { return nAtom_; }
199 
200  /*
201  * Return the number of molecules (maximum molecule id + 1).
202  */
203  inline int Species::size() const
204  { return molecules_.size(); }
205 
206  /*
207  * Return the maximum number of molecules (memory capacity).
208  */
209  inline int Species::capacity() const
210  { return capacity_; }
211 
212  /*
213  * Serialize to/from an archive.
214  */
215  template <class Archive>
216  void Species::serialize(Archive& ar, const unsigned int version)
217  {
218  ar & nAtom_;
219  ar & capacity_;
220  if (Archive::is_loading()) {
221  initialize();
222  }
223  }
224 
225 }
226 #endif
int nAtom() const
Get number of atoms per molecule for this Species.
void serialize(Archive &ar, const unsigned int version)
Serialize this ParamComponent as a string.
virtual ~Species()
Destructor.
std::istream & operator>>(std::istream &in, Group< N > &group)
istream extractor (>>) for a Group.
std::ostream & operator<<(std::ostream &out, const Group< N > &group)
ostream inserter (<<) for a Group.
int nAtom_
Number of atoms per molecule.
Species()
Constructor.
Utility classes for scientific computation.
Definition: accumulators.mod:1
An Molecule has a sequence of atoms, and belongs to an Species.
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
Single-processor classes for pre- and post-processing MD trajectories.
bool isValid() const
Return true if Species is valid, or throw an Exception.
void setId(int id)
Set integer id for this Species.
A point particle in an MD simulation.
int id_
Integer index for this Species.
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
int id() const
Get integer id of this Species.
int capacity() const
Maximum allowed number of molecules for this Species.
Dynamically allocated array with variable logical size.
Definition: DSArray.h:30
A Species represents a set of chemically similar molecules.