8 #include "SmpConfigIo.h" 9 #include <mcMd/simulation/Simulation.h> 10 #include <mcMd/simulation/System.h> 11 #include <mcMd/species/SpeciesMutator.h> 12 #include <mcMd/chemistry/Molecule.h> 13 #include <mcMd/chemistry/Atom.h> 15 #include <mcMd/tethers/TetherMaster.h> 18 #include <mcMd/links/LinkMaster.h> 20 #include <simp/species/Species.h> 21 #include <util/param/Label.h> 22 #include <util/misc/FlagSet.h> 23 #include <util/format/Int.h> 65 int nAtomSpecies, nAtomMolecule;
67 Label speciesLabel(
"SPECIES",
false);
68 if (speciesLabel.
match(in)) {
77 int nSpeciesIn, iSpeciesIn;
78 in >>
Label(
"nSpecies") >> nSpeciesIn;
81 Label speciesLabel(
"species");
82 Label nMoleculeLabel(
"nMolecule");
83 for (
int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
84 in >>
Label(
"species") >> iSpeciesIn;
86 in >>
Label(
"nMolecule") >> nMoleculeSpecies[iSpecies];
95 firstAtomIds[iSpecies] = nAtomTot;
96 nAtomMolecule = speciesPtr->
nAtom();
97 nAtomSpecies = nMoleculeSpecies[iSpecies]*nAtomMolecule;
98 nAtomTot += nAtomSpecies;
110 for (
int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
112 nMoleculeSpecies[iSpecies] = speciesPtr->
capacity();
113 firstAtomIds[iSpecies+1] = nAtomTot;
114 nAtomMolecule = speciesPtr->
nAtom();
115 nAtomSpecies = nMoleculeSpecies[iSpecies]*nAtomMolecule;
116 nAtomTot += nAtomSpecies;
121 in >>
Label(
"BOUNDARY");
126 Label orderedLabel(
"ordered",
false);
127 bool isOrdered = orderedLabel.
match(in);
128 std::string formatString;
129 in >> Label(
"format") >> formatString;
132 in >> Label(
"nAtom") >> nAtom;
138 bool hasAtomIndex = atomFormat.
isActive(
'i');
139 bool hasAtomContext = atomFormat.
isActive(
'm');
140 bool hasAtomTypeId = atomFormat.
isActive(
't');
141 bool hasAtomPosition = atomFormat.
isActive(
'p');
142 bool hasAtomVelocity = atomFormat.
isActive(
'v');
143 bool hasAtomShift = atomFormat.
isActive(
's');
153 int atomIndex, iAtom, count, atomTypeId;
154 int cSpeciesId, cMoleculeId, cAtomId;
158 for (iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
160 nAtomMolecule = speciesPtr->
nAtom();
161 for (iMol = 0; iMol < nMoleculeSpecies[iSpecies]; ++iMol) {
166 if (molPtr != &
system().molecule(iSpecies, iMol)) {
172 molPtr->
begin(atomIter);
173 for ( ; atomIter.
notEnd(); ++atomIter) {
181 if (hasAtomContext) {
200 atomIter->setTypeId(atomTypeId);
202 in >> atomIter->position();
204 if (hasAtomVelocity) {
205 in >> atomIter->velocity();
211 atomIter->shift() = shift;
217 in >> atomIter->shift();
244 out << endl <<
"nSpecies " << nSpecies;
245 int iMolecule, nMolecule;
250 for (
int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
251 out << endl <<
"species " << iSpecies;
253 out << endl <<
" nMolecule " << nMolecule;
256 nAtom = speciesPtr->
nAtom();
257 nAtomTot += nMolecule*nAtom;
262 out << endl <<
"BOUNDARY";
266 out << endl <<
"ATOM";
267 out << endl <<
"ordered";
268 out << endl <<
"format imtpv";
269 out << endl <<
"nAtom " << nAtomTot;
274 for (
int iSpecies = 0; iSpecies < nSpecies; ++iSpecies) {
278 for ( ; molIter.
notEnd(); ++molIter) {
280 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter) {
282 out << atomId <<
" ";
283 out << iSpecies <<
" " << iMolecule <<
" " << iAtom <<
" ";
284 out << atomIter->typeId();
285 out << endl << atomIter->position();
286 out << endl << atomIter->velocity();
virtual void read(std::istream &in)
Read configuration (particle positions) from file.
Boundary & boundary() const
Get the Boundary.
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
int nAtom() const
Get number of atoms per molecule for this Species.
bool notEnd() const
Is the current pointer not at the end of the array?
void writeStructure(std::ostream &out, std::string indent=std::string())
Write molecular structure in config/topology file format.
void begin(AtomIterator &iterator)
Set an Molecule::AtomIterator to first Atom in this Molecule.
A set of interacting Molecules enclosed by a Boundary.
Forward iterator for a PArray.
Classes used by all simpatico molecular simulations.
Molecule & getMolecule(int speciesId)
Get a new molecule from a reservoir of unused Molecule objects.
static bool isClear()
Is the input buffer clear?
bool isActive(char c) const
Is the flag associated with character c active?
Forward const iterator for an Array or a C array.
int nMolecule(int speciesId) const
Get the number of molecules of one Species in this System.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void addMolecule(Molecule &molecule)
Add a Molecule to this System.
virtual ~SmpConfigIo()
Destructor.
Utility classes for scientific computation.
System & system() const
Get a reference to the parent System.
SmpConfigIo(System &system)
Constructor.
bool matchStructure(std::istream &in)
Read structure, return true iff it matches existing structure.
void shift(Vector &r) const
Shift Cartesian Vector r to its primary image.
int atomTypeId(int iAtom) const
Get atom type index for a specific atom, by local atom index.
Forward iterator for an Array or a C array.
A label string in a file format.
Simulation & simulation() const
Get a reference to the parent Simulation.
bool notEnd() const
Is the current pointer not at the end of the array?
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
bool match(std::istream &in)
Read and attempt to match next word in an input stream.
void setActualOrdered(std::string actual)
Set the string of actual flag characters.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
An IntVector is an integer Cartesian vector.
int capacity() const
Maximum allowed number of molecules for this Species.
void allocate(int capacity)
Allocate the underlying C array.
A physical molecule (a set of covalently bonded Atoms).
bool notEnd() const
Is this not the end of the array?
A Species represents a set of chemically similar molecules.
Species & species(int i)
Get a specific Species by reference.
virtual void write(std::ostream &out)
Write configuration (particle positions) to file.
A set of boolean variables represented by characters.
System configuration file reader and writer.