Simpatico  v1.10
ConfigReader.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "ConfigReader.h"
9 #include <tools/storage/Configuration.h>
10 
11 #include <iostream>
12 
13 namespace Tools
14 {
15 
16  using namespace Util;
17 
18  /*
19  * Constructor.
20  */
22  : configurationPtr_(0)
23  { setClassName("ConfigReader"); }
24 
25  /*
26  * Constructor.
27  */
29  bool needsAuxiliaryFile)
30  : configurationPtr_(&configuration),
31  needsAuxiliaryFile_(needsAuxiliaryFile)
32  { setClassName("ConfigReader"); }
33 
34  /*
35  * Destructor.
36  */
38  {}
39 
40  /*
41  * Attempt to set atom context info, assuming ordered atom ids.
42  */
44  {
45  int nSpecies = configuration().nSpecies();
46  if (nSpecies > 0) {
47  Species* speciesPtr = 0;
48 
49  // Check total number of atoms
50  int nFill = 0;
51  for (int i = 0; i < nSpecies; ++i) {
52  speciesPtr = &configuration().species(i);
53  nFill += speciesPtr->nAtom()*speciesPtr->capacity();
54  speciesPtr->clear();
55  }
56  AtomStorage* storagePtr = &configuration().atoms();
57  if (storagePtr->size() != nFill) {
58  std::cout << "Warning: Mismatched numbers of atoms" << std::endl;
59  return false; // failure
60  }
61 
62  // Set speciesId, moleculeId and atomId for each Atom
63  Atom* atomPtr;
64  int speciesId, moleculeId, atomId, nMolecule, nAtom;
65  int id = 0;
66  for (speciesId = 0; speciesId < nSpecies; ++speciesId) {
67  speciesPtr = &configuration().species(speciesId);
68  nMolecule = speciesPtr->capacity();
69  nAtom = speciesPtr->nAtom();
70  for (moleculeId = 0; moleculeId < nMolecule; ++moleculeId) {
71  for (atomId = 0; atomId < nAtom; ++atomId) {
72  atomPtr = storagePtr->ptr(id);
73  if (!atomPtr) {
74  std::cout << "Warning: missing atom" << std::endl;
75  return false;
76  }
77  atomPtr->speciesId = speciesId;
78  atomPtr->moleculeId = moleculeId;
79  atomPtr->atomId = atomId;
80  ++id;
81  }
82  }
83  }
84 
85  }
86 
87  // Indicate successful completion
88  return true;
89  }
90 
91  /*
92  * Add all atoms to Species containers and associated molecules.
93  */
95  {
96  int nSpecies = configuration().nSpecies();
97  if (nSpecies > 0) {
98  for (int i = 0; i < nSpecies; ++i) {
99  configuration().species(i).clear();
100  }
101  int speciesId;
103  configuration().atoms().begin(iter);
104  for ( ; iter.notEnd(); ++iter) {
105  speciesId = iter->speciesId;
106  if (speciesId < 0) {
107  UTIL_THROW("Negative speciesId");
108  }
109  if (speciesId >= nSpecies) {
110  UTIL_THROW("speciesId >= nSpecies");
111  }
112  configuration().species(speciesId).addAtom(*iter);
113  }
114  for (int i = 0; i < nSpecies; ++i) {
116  }
117  }
118  }
119 
120 }
int speciesId
Index for species of parent molecule.
int nAtom() const
Get number of atoms per molecule for this Species.
Container for a set of atoms.
bool notEnd() const
Is the current pointer not at the end of the array?
Definition: ArrayIterator.h:83
ConfigReader()
Default constructor.
bool needsAuxiliaryFile() const
Return true if an auxiliary file is needed.
Definition: ConfigReader.h:106
int size() const
Get number of atoms.
Atom * ptr(int id)
Get a pointer to an atom by global id.
AtomStorage & atoms()
Get the AtomStorage.
An instantaneous molecular dynamics configuration.
Definition: Configuration.h:40
bool setAtomContexts()
Set atom context data for all atoms, assuming consecutive ids.
int nSpecies() const
Number of species.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
Single-processor classes for pre- and post-processing MD trajectories.
virtual ~ConfigReader()
Destructor.
int atomId
Index of atom within its molecule.
bool isValid() const
Return true if Species is valid, or throw an Exception.
A point particle in an MD simulation.
void begin(Iterator &iter)
Initialize an iterator for atoms.
void addAtomsToSpecies()
Add all atoms to Species containers and associated molecules.
void setClassName(const char *className)
Set class name string.
int capacity() const
Maximum allowed number of molecules for this Species.
Species & species(int i)
Get a particular species identified by index.
A Species represents a set of chemically similar molecules.
Configuration & configuration()
Get parent Configuration by reference.
Definition: ConfigReader.h:89
int moleculeId
Index of molecule with its species.