/* * Read parameter speciesId. */ void EndSwapMove::readParameters(std::istream& in) { readProbability(in); read<int>(in, "speciesId", speciesId_); Species* speciesPtr = &(simulation().species(speciesId_)); int nAtom = speciesPtr->nAtom(); // Preconditions if (speciesPtr->isMutable()) { UTIL_THROW("EndSwapMove on mutable Species"); } Linear* linearPtr = dynamic_cast<Linear*>(speciesPtr); if (linearPtr == 0) { UTIL_THROW("EndSwapMove on Species that is not a Linear"); } // Allocate memory atomTypeIds_.allocate(nAtom); positions_.allocate(nAtom); // Set array of atom type ids for (int i = 0; i < nAtom; ++i) { atomTypeIds_[i] = speciesPtr->atomTypeId(i); } }
/* * Generate random molecules */ bool Generator::generate(int nMolecule, const DArray<double>& diameters, CellList& cellList) { // Preconditions UTIL_CHECK(nMolecule <= species().capacity()); UTIL_CHECK(cellList.atomCapacity() == simulation().atomCapacity()); // Attempt to place all molecules in Species int speciesId = species().id(); int maxAttempt = 200; int iAttempt; bool success; bool isMutable; Species* speciesPtr; for (int iMol = 0; iMol < nMolecule; ++iMol) { Molecule &newMolecule= simulation().getMolecule(speciesId); system().addMolecule(newMolecule); speciesPtr = &system().simulation().species(speciesId); isMutable = speciesPtr->isMutable(); if (isMutable) { speciesPtr->mutator().setMoleculeState(newMolecule, 0); } success = false; iAttempt = 0; while (!success && iAttempt < maxAttempt) { success = attemptPlaceMolecule(newMolecule, diameters, cellList); ++iAttempt; } if (!success) { system().removeMolecule(newMolecule); Log::file() << "Failed to insert Linear molecule " << iMol << "\n"; return false; } } return true; }
/* * Load from archive. */ void EndSwapMove::loadParameters(Serializable::IArchive& ar) { McMove::loadParameters(ar); loadParameter<int>(ar, "speciesId", speciesId_); ar & atomTypeIds_; // Validate Species* speciesPtr = &(simulation().species(speciesId_)); int nAtom = speciesPtr->nAtom(); if (speciesPtr->isMutable()) { UTIL_THROW("EndSwapMove applied to mutable species"); } Linear* linearPtr = dynamic_cast<Linear*>(speciesPtr); if (linearPtr == 0) { UTIL_THROW("EndSwapMove applied to species that is not Linear"); } if (nAtom != atomTypeIds_.capacity()) { UTIL_THROW("Inconsistent capacity for atomTypeIds array"); } positions_.allocate(nAtom); }
/* * Write the configuration file. */ void McMdConfigIo::write(std::ostream &out) { using std::endl; // Write Boundary dimensions out << "BOUNDARY" << endl << endl; out << boundary() << endl; // Write atomic positions System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; Species* speciesPtr; int iSpecies, iMolecule; out << endl << "MOLECULES" << endl; for (iSpecies = 0; iSpecies < simulation().nSpecies(); ++iSpecies) { out << endl; out << "species " << iSpecies << endl; out << "nMolecule " << system().nMolecule(iSpecies) << endl; speciesPtr = &simulation().species(iSpecies); iMolecule = 0; system().begin(iSpecies, molIter); for ( ; molIter.notEnd(); ++molIter) { out << endl; out << "molecule " << iMolecule << endl; if (speciesPtr->isMutable()) { speciesPtr->mutator().writeMoleculeState(out, *molIter); } for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) { //out << atomIter->position() << endl; writeAtom(out, *atomIter); } ++iMolecule; } } #ifdef INTER_TETHER { // Scope for local variables // Write Tethers Tether* tetherPtr; Atom* atomPtr; Molecule* molPtr; int iTether, nTether, iAtom; out << std::endl; out << "TETHERS" << endl << endl; nTether = system().tetherMaster().nTether(); out << Label("nTether") << nTether << std::endl; for (iTether = 0; iTether < nTether; ++iTether) { tetherPtr = &(system().tetherMaster().tether(iTether)); atomPtr = &tetherPtr->atom(); molPtr = &atomPtr->molecule(); iAtom = atomPtr->indexInMolecule(); iMolecule = system().moleculeId(*molPtr); iSpecies = molPtr->species().id(); out << Int(iSpecies,5) << Int(iMolecule,9) << Int(iAtom,6) << tetherPtr->anchor() << std::endl; } } #endif #ifdef MCMD_LINK { // Scope for local variables // Write Links Link* linkPtr; Atom* atomPtr; Molecule* molPtr; int iLink, nLink, iAtom; out << std::endl; out << "LINKS" << endl << endl; nLink = system().linkMaster().nLink(); out << Label("nLink") << nLink << std::endl; for (iLink = 0; iLink < nLink; ++iLink) { linkPtr = &(system().linkMaster().link(iLink)); // Output species, molecule, atom ids for atom 0 atomPtr = &(linkPtr->atom0()); molPtr = &atomPtr->molecule(); iAtom = atomPtr->indexInMolecule(); iMolecule = system().moleculeId(*molPtr); iSpecies = molPtr->species().id(); out << Int(iSpecies,8) << Int(iMolecule,8) << Int(iAtom,8); out << " "; // Output species, molecule, atom ids for atom 1 atomPtr = &(linkPtr->atom1()); molPtr = &atomPtr->molecule(); iAtom = atomPtr->indexInMolecule(); iMolecule = system().moleculeId(*molPtr); iSpecies = molPtr->species().id(); out << Int(iSpecies,8) << Int(iMolecule,8) << Int(iAtom,8); out << " "; out << Int(linkPtr->typeId(),8) << std::endl; } } #endif }