1 #ifndef MCMD_CLUSTER_HISTOGRAM_CPP 2 #define MCMD_CLUSTER_HISTOGRAM_CPP 11 #include "ClusterHistogram.h" 12 #include <mcMd/simulation/System.h> 13 #include <mcMd/simulation/Simulation.h> 14 #include <mcMd/chemistry/Molecule.h> 15 #include <mcMd/chemistry/Atom.h> 17 #include <simp/boundary/Boundary.h> 18 #include <simp/species/Species.h> 20 #include <util/misc/FileMaster.h> 21 #include <util/archives/Serializable_includes.h> 22 #include <util/format/Int.h> 23 #include <util/format/Dbl.h> 24 #include <util/misc/ioUtil.h> 25 #include <util/space/Tensor.h> 26 #include <util/containers/DArray.h> 55 read<int>(in,
"speciesId", speciesId_);
59 if (speciesId_ >=
system().simulation().nSpecies()) {
63 read<int>(in,
"atomTypeId", atomTypeId_);
64 if (atomTypeId_ < 0) {
67 if (atomTypeId_ >=
system().simulation().nAtomType()) {
71 read<double>(in,
"cutoff", cutoff_);
77 identifier_.
initialize(speciesId_, atomTypeId_, cutoff_);
78 read<int>(in,
"histMin", histMin_);
79 read<int>(in,
"histMax", histMax_);
83 isInitialized_ =
true;
94 loadParameter<int>(ar,
"speciesId", speciesId_);
98 if (speciesId_ >=
system().simulation().nSpecies()) {
102 loadParameter<int>(ar,
"atomTypeId", atomTypeId_);
103 if (atomTypeId_ < 0) {
107 loadParameter<double>(ar,
"cutoff", cutoff_);
112 identifier_.
initialize(speciesId_, atomTypeId_, cutoff_);
113 loadParameter<int>(ar,
"histMin", histMin_);
114 loadParameter<int>(ar,
"histMax", histMax_);
119 isInitialized_ =
true;
142 if (!isInitialized_)
UTIL_THROW(
"Object is not initialized");
156 for (
int i = 0; i < identifier_.
nCluster(); i++) {
167 for (
int i = 0; i < identifier_.
nCluster(); i++) {
168 thisCluster = identifier_.
cluster(i);
169 thisClusterStart = thisCluster.
head();
170 outputFile_ << i <<
" " ;
172 while (thisClusterStart) {
173 next = thisClusterStart->
next();
174 thisMolecule = thisClusterStart->
molecule();
175 outputFile_ << thisMolecule.
id() <<
" ";
176 thisClusterStart = next;
195 for (
int i = 0; i < identifier_.
nCluster(); i++) {
196 thisCluster = identifier_.
cluster(i);
197 outputFile_ << i <<
" " ;
200 outputFile_ << clusterCOM;
202 allCOMs[i] = clusterCOM;
205 allMoments[i] = moment;
209 for (
int i = 0; i < identifier_.
nCluster(); i++) {
210 outputFile_ << i <<
" " << allMoments[i] <<
"\n";
230 int min = hist_.
min();
231 int nBin = hist_.
nBin();
232 for (
int i = 0; i < nBin; ++i) {
233 outputFile_ <<
Int(i + min) <<
" " 234 <<
Dbl(
double(hist_.
data()[i])/
double(nSample_)) <<
"\n";
virtual void save(Serializable::OArchive &ar)
Load parameters to archive.
std::string toString(int n)
Return string representation of an integer.
A Vector is a Cartesian vector.
Cluster & cluster(int id)
Get a specific cluster, indexed in the order identified.
int nCluster() const
Get number of clusters.
virtual void initialize(int speciesId, int atomTypeId, double cutoff)
Clear accumulator.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from archive.
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.
ClusterLink * next() const
Get pointer to next link in linked list.
Classes used by all simpatico molecular simulations.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
int id() const
Get the index for this Molecule (unique in species).
A Tensor represents a Cartesian tensor.
Forward const iterator for an Array or a C array.
Saving / output archive for binary ostream.
virtual void sample(long iStep)
Identify clusters in configuration.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
ClusterLink * head() const
Get a pointer to the first link in the linked list.
void clear()
Clear (i.e., zero) previously allocated histogram.
void setParam(int min, int max)
Set parameters and initialize.
ClusterHistogram(System &system)
Constructor.
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
void sample(int value)
Sample a value.
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
virtual void setup()
Clear accumulator.
Wrapper for an int, for formatted ostream output.
virtual void readParameters(std::istream &in)
Read parameters from file, and allocate data array.
Molecule & molecule() const
Get associated molecule by reference.
virtual void save(Serializable::OArchive &ar)
Save state to archive.
const DArray< long > & data() const
Get histogram array.
void identifyClusters()
Identify all clusters (main operation).
int nBin() const
Get the number of bins.
Template for Analyzer associated with one System.
Dynamically allocatable contiguous array template.
Saving archive for binary istream.
int size() const
Get the number of molecules or links in the cluster.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setClassName(const char *className)
Set class name string.
FileMaster & fileMaster()
Get the FileMaster by reference.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
int min() const
Get minimum value in range of histogram.
const std::string & outputFileName() const
Return outputFileName string.
void allocate(int capacity)
Allocate the underlying C array.
Vector clusterCOM(int atomTypeInCluster, Boundary const &boundary)
Return the cluster COM.
A physical molecule (a set of covalently bonded Atoms).
Tensor momentTensor(int atomTypeInCluster, Boundary const &boundary)
Return the cluster radius of gyration tensor.
virtual void loadParameters(Serializable::IArchive &ar)
Load state from an archive.
virtual void output()
Output results at end of simulation.