8 #include "BlockRadiusGyration.h" 9 #include <mcMd/simulation/Simulation.h> 10 #include <simp/species/Species.h> 11 #include <mcMd/chemistry/Molecule.h> 12 #include <mcMd/chemistry/Atom.h> 13 #include <simp/boundary/Boundary.h> 14 #include <util/misc/FileMaster.h> 15 #include <util/archives/Serializable_includes.h> 17 #include <util/format/Dbl.h> 52 for (i = 0; i < nAtomType_; ++i) {
53 for (j = i+1; j < nAtomType_; ++j) {
57 accumulators_.allocate(nAtomType_ + nAtomTypePairs_);
59 read<int>(in,
"nSamplePerBlock", nSamplePerBlock_);
60 for (i = 0; i < nAtomType_+nAtomTypePairs_; ++i) {
61 accumulators_[i].setNSamplePerBlock(nSamplePerBlock_);
65 if (accumulators_[0].nSamplePerBlock()) {
69 read<int>(in,
"speciesId", speciesId_);
74 if (speciesId_ >=
system().simulation().nSpecies()) {
79 nAtom_ = speciesPtr_->
nAtom();
82 positions_.allocate(nAtom_);
85 rCom_.allocate(nAtomType_);
93 isInitialized_ =
true;
103 loadParameter<int>(ar,
"nSamplePerBlock", nSamplePerBlock_);
104 loadParameter<int>(ar,
"speciesId", speciesId_);
107 ar & nAtomTypePairs_;
112 if (speciesId_ < 0) {
115 if (speciesId_ >=
system().simulation().nSpecies()) {
118 if (nAtom_ != speciesPtr_->
nAtom()) {
121 if (nAtomType_ !=
system().simulation().nAtomType()) {
127 for (i = 0; i < nAtomType_; ++i) {
128 for (j = i+1; j < nAtomType_; ++j) {
132 if (nAtomTypePairs_ != nPairTypes) {
138 positions_.allocate(nAtom_);
139 rCom_.allocate(nAtomType_);
142 dRSqPair_.
allocate(nAtomTypePairs_);
143 accumulators_.allocate(nAtomType_ + nAtomTypePairs_);
144 for (
int i = 0; i < nAtomType_+nAtomTypePairs_; ++i) {
145 accumulators_[i].setNSamplePerBlock(nSamplePerBlock_);
151 if (accumulators_[0].nSamplePerBlock()) {
154 isInitialized_ =
true;
168 if (!isInitialized_)
UTIL_THROW(
"Object is not initialized");
170 for (
int i = 0; i < nAtomType_ + nAtomTypePairs_; ++i) {
171 accumulators_[i].clear();
184 int i, j, k, l, m, typeId, nMolecule;
187 for (i = 0; i < nAtomType_; ++i) {
190 for (j = i+1; j < nAtomType_; ++j) {
192 dRSqPair_[k-1] = 0.0;
198 for (j = 0 ; j < nAtom_; j++) {
200 iTypeNAtom_[typeId] += 1;
207 for (j = 0; j < nAtomType_; ++j) {
214 rCom_[typeId] += positions_[0];
215 for (j = 1 ; j < nAtom_; j++) {
220 positions_[j] = positions_[j-1];
222 rCom_[typeId] += positions_[j];
224 for (l = 0; l < nAtomType_; ++l) {
225 rCom_[l] /= double(iTypeNAtom_[l]);
228 for (l = 0; l < nAtomType_; ++l) {
229 for (m = l+1; m < nAtomType_; ++m) {
232 dRSqPair_[k-1] += dR.
square();
235 for (j = 0 ; j < nAtom_; j++) {
237 dR.
subtract(positions_[j], rCom_[typeId]);
238 dRSq_[typeId] += dR.
square();
243 for (i = 0; i < nAtomType_; ++i) {
244 dRSq_[i] /= double(nMolecule);
245 dRSq_[i] /= double(iTypeNAtom_[i]);
246 accumulators_[i].sample(dRSq_[i]);
247 outputFile_ <<
Dbl(dRSq_[i]) <<
" ";
248 for (j = i+1; j < nAtomType_; ++j) {
250 dRSqPair_[k-1] /= double(nMolecule);
251 accumulators_[nAtomType_+k-1].sample(dRSqPair_[k-1]);
252 outputFile_ <<
Dbl(dRSqPair_[k-1]) <<
" ";
255 outputFile_ << std::endl;
268 if (accumulators_[0].nSamplePerBlock()) {
280 for (i = 0; i < nAtomType_; ++i) {
281 accumulators_[i].output(outputFile_);
282 for (j = i+1; j < nAtomType_; ++j) {
284 accumulators_[nAtomType_+k-1].output(outputFile_);
285 outputFile_ << std::endl;
286 outputFile_ << std::endl;
A Vector is a Cartesian vector.
virtual void save(Serializable::OArchive &ar)
Save state to archive.
int nAtom() const
Get number of atoms per molecule for this Species.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
BlockRadiusGyration(System &system)
Constructor.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from archive.
virtual void output()
Output results at end of simulation.
A set of interacting Molecules enclosed by a Boundary.
System & system()
Return reference to parent system.
Wrapper for a double precision number, for formatted ostream output.
Classes used by all simpatico molecular simulations.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
Saving / output archive for binary ostream.
Molecule & molecule(int speciesId, int moleculeId)
Get a specific Molecule in this System, by integer index.
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.
Simulation & simulation() const
Get the parent Simulation by reference.
int typeId() const
Get type index for this Atom.
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
virtual void sample(long iStep)
Evaluate squared radii of gyration for all molecules, add to ensemble.
virtual void setup()
Clear accumulator.
Template for Analyzer associated with one System.
Boundary & boundary() const
Get the Boundary by reference.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual void readParameters(std::istream &in)
Read parameters from file, and allocate data array.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
void setClassName(const char *className)
Set class name string.
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
FileMaster & fileMaster()
Get the FileMaster by reference.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
const std::string & outputFileName() const
Return outputFileName string.
void allocate(int capacity)
Allocate the underlying C array.
A physical molecule (a set of covalently bonded Atoms).
const Vector & position() const
Get the position Vector by const reference.
int nAtomType() const
Get the number of atom types.
Species & species(int i)
Get a specific Species by reference.
double square() const
Return square magnitude of this vector.