8 #include "LammpsConfigIo.h" 9 #include <mcMd/simulation/System.h> 10 #include <mcMd/simulation/Simulation.h> 11 #include <mcMd/chemistry/Molecule.h> 12 #include <mcMd/chemistry/Atom.h> 14 #include <simp/species/Species.h> 16 #include <util/space/Vector.h> 17 #include <util/space/IntVector.h> 18 #include <util/param/Label.h> 19 #include <util/format/Format.h> 20 #include <util/format/Int.h> 21 #include <util/format/Dbl.h> 22 #include <util/misc/ioUtil.h> 54 int speciesCapacity = 0;
57 for (iSpec = 0; iSpec < nSpecies; ++iSpec) {
59 speciesCapacity = speciesPtr->
capacity();
60 atomCapacity += speciesCapacity*speciesPtr->
nAtom();
62 bondCapacity += speciesCapacity*speciesPtr->
nBond();
68 std::getline(in, line);
76 in >> nAtom >>
Label(
"atoms");
77 in >> nBond >> Label(
"bonds");
78 in >> nAngle >> Label(
"angles");
79 in >> nDihedral >> Label(
"dihedrals");
80 in >> nImproper >> Label(
"impropers");
87 if (nAtom != atomCapacity) {
90 if (nBond != bondCapacity) {
100 in >> nAtomType >> Label(
"atom") >> Label(
"types");
101 in >> nBondType >> Label(
"bond") >> Label(
"types");
102 in >> nAngleType >> Label(
"angle") >> Label(
"types");
103 in >> nDihedralType >> Label(
"dihedral") >> Label(
"types");
104 in >> nImproperType >> Label(
"improper") >> Label(
"types");
107 UTIL_THROW(
"nAtomType > simulation().nAtomType()");
113 in >> min[0] >> max[0] >> Label(
"xlo") >> Label(
"xhi");
114 in >> min[1] >> max[1] >> Label(
"ylo") >> Label(
"yhi");
115 in >> min[2] >> max[2] >> Label(
"zlo") >> Label(
"zhi");
122 in >> Label(
"Masses");
123 for (i = 0; i < nAtomType; ++i) {
124 in >> atomTypeId >> mass;
132 in >> Label(
"Atoms");
136 int atomId, molId, iMol, nMolecule;
137 for (iSpec=0; iSpec < nSpecies; ++iSpec) {
140 for (iMol = 0; iMol < nMolecule; ++iMol) {
144 if (molPtr != &
system().molecule(iSpec, iMol)) {
149 for (molPtr->
begin(atomIter); atomIter.
notEnd(); ++atomIter) {
151 in >> atomId >> molId >> atomTypeId;
152 if (atomId != atomIter->id() + 1)
155 in >> atomIter->position();
158 atomIter->position() += min;
172 out <<
"LAMMPS data file" <<
"\n";
177 int iSpec, nMolecule;
185 nAtom += nMolecule*(speciesPtr->
nAtom());
187 nBond += nMolecule*(speciesPtr->
nBond());
190 nAngle += nMolecule*(speciesPtr->
nAngle());
193 nDihedral += nMolecule*(speciesPtr->
nDihedral());
199 out <<
Int(nAtom) <<
" atoms " <<
"\n";
200 out <<
Int(nBond) <<
" bonds " <<
"\n";
201 out <<
Int(nAngle) <<
" angles " <<
"\n";
202 out <<
Int(nDihedral) <<
" dihedrals" <<
"\n";
203 out <<
Int(0) <<
" impropers" <<
"\n";
208 out <<
Int(
simulation().nAtomType()) <<
" atom types" <<
"\n";
211 int nDihedralType = 0;
221 out <<
Int(nBondType) <<
" bond types" <<
"\n";
222 out <<
Int(nAngleType) <<
" angle types" <<
"\n";
223 out <<
Int(nDihedralType) <<
" dihedral types" <<
"\n";
224 out <<
Int(0) <<
" improper types" <<
"\n";
231 out <<
Dbl(0.0) <<
Dbl(lengths[0]) <<
" xlo xhi" <<
"\n";
232 out <<
Dbl(0.0) <<
Dbl(lengths[1]) <<
" ylo yhi" <<
"\n";
233 out <<
Dbl(0.0) <<
Dbl(lengths[2]) <<
" zlo zhi" <<
"\n";
238 out <<
"Masses" <<
"\n";
241 out <<
Int(iType+1, 5) <<
Dbl(1.0) <<
"\n";
248 out <<
"Atoms" <<
"\n";
256 for (molIter->begin(atomIter); atomIter.
notEnd(); ++atomIter) {
257 out <<
Int( atomIter->id() + 1, 8 ) <<
Int( molIter->id() + 1, 8 );
258 out <<
Int( atomIter->typeId() + 1, 5 );
259 out << atomIter->position();
261 out <<
Int(shift, 4);
271 out <<
"Bonds" <<
"\n";
277 for (molIter->begin(bondIter); bondIter.
notEnd(); ++bondIter) {
278 out <<
Int(iBond, 8 ) <<
Int(bondIter->typeId() + 1, 5);
279 out <<
Int(bondIter->atom(0).id() + 1, 8);
280 out <<
Int(bondIter->atom(1).id() + 1, 8);
292 out <<
"Angles" <<
"\n";
298 for (molIter->begin(angleIter); angleIter.
notEnd(); ++angleIter) {
299 out <<
Int(iAngle, 8) <<
Int(angleIter->typeId() + 1, 5);
300 out <<
Int(angleIter->atom(0).id() + 1, 8);
301 out <<
Int(angleIter->atom(1).id() + 1, 8);
302 out <<
Int(angleIter->atom(2).id() + 1, 8);
314 out <<
"Dihedrals" <<
"\n";
320 molIter->begin(dihedralIter);
321 for ( ; dihedralIter.
notEnd(); ++dihedralIter) {
322 out <<
Int(iDihedral, 8);
323 out << Int(dihedralIter->typeId() + 1, 5);
324 out << Int(dihedralIter->atom(0).id() + 1, 8);
325 out << Int(dihedralIter->atom(1).id() + 1, 8);
326 out << Int(dihedralIter->atom(2).id() + 1, 8);
327 out << Int(dihedralIter->atom(3).id() + 1, 8);
Boundary & boundary() const
Get the Boundary.
const int Dimension
Dimensionality of space.
A Vector is a Cartesian vector.
virtual ~LammpsConfigIo()
Destructor.
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 setOrthorhombic(const Vector &lengths)
Set unit cell dimensions for orthorhombic boundary.
const Vector & lengths() const
Get Vector of unit cell lengths by const reference.
void begin(AtomIterator &iterator)
Set an Molecule::AtomIterator to first Atom in this Molecule.
A set of interacting Molecules enclosed by a Boundary.
Wrapper for a double precision number, for formatted ostream output.
Classes used by all simpatico molecular simulations.
Molecule & getMolecule(int speciesId)
Get a new molecule from a reservoir of unused Molecule objects.
int nDihedral() const
Get number of dihedrals per molecule for this Species.
int nBondType() const
Get the number of bond types.
int nMolecule(int speciesId) const
Get the number of molecules of one Species in this System.
void read(std::istream &in)
Read configuration (particle positions) from file.
#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.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
System & system() const
Get a reference to the parent System.
Wrapper for an int, for formatted ostream output.
Forward iterator for an Array or a C array.
Forward iterator for a PArray.
int nAngleType() const
Get the number of angle types.
A label string in a file format.
Simulation & simulation() const
Get a reference to the parent Simulation.
int nDihedralType() const
Get the number of dihedral types.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void write(std::ostream &out)
Write configuration (particle positions) to file.
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
#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.
LammpsConfigIo(System &system)
Constructor.
A physical molecule (a set of covalently bonded Atoms).
int nAtomType() const
Get the number of atom types.
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.
Species & species(int i)
Get a specific Species by reference.
System configuration file reader and writer.