39 UTIL_THROW(
"Species already initialized: capacity_ != 0");
42 UTIL_THROW(
"Species already initialized: nAtom_ != 0");
49 void Species::initialize()
52 if (molecules_.capacity() != 0) {
53 UTIL_THROW(
"Species::molecules_ already allocated");
55 if (atomPtrs_.capacity() != 0) {
56 UTIL_THROW(
"Species::atomPtrs_ already allocated");
59 UTIL_THROW(
"Species::capacity_ <= 0: Value not set");
62 UTIL_THROW(
"Species::nAtom_ <= 0: Value not set");
66 atomPtrs_.allocate(capacity_*
nAtom_);
67 for (
int i=0; i < atomPtrs_.capacity(); ++i) {
72 molecules_.allocate(capacity_);
75 molecules_.resize(capacity_);
76 Atom** atomPtr = &atomPtrs_[0];
77 for (
int i = 0; i < capacity_; ++i) {
78 molecules_[i].atoms_ = atomPtr;
79 molecules_[i].id_ = i;
80 molecules_[i].nAtom_ = 0;
81 molecules_[i].speciesPtr_ =
this;
93 for (
int i = 0; i < atomPtrs_.capacity(); ++i) {
96 for (
int i = 0; i < molecules_.size(); ++i) {
97 molecules_[i].nAtom_ = 0;
105 void Species::addAtom(
Atom& atom)
115 if (mId >= capacity_) {
124 int gid = mId*
nAtom_ + aId;
125 if (atomPtrs_[gid] != 0) {
128 atomPtrs_[gid] = &atom;
129 if (mId >= molecules_.size()) {
130 molecules_.resize(mId+1);
132 ++molecules_[mId].nAtom_;
139 { molecules_.begin(iterator); }
147 if (molecules_.capacity() != capacity_) {
150 if (atomPtrs_.capacity() != capacity_*
nAtom_) {
155 if (molecules_.size() > 0) {
159 for (im = 0; im < molecules_.size(); ++im) {
160 mPtr = &(molecules_[im]);
161 if (mPtr->atoms_ != &atomPtrs_[0] + im*
nAtom_) {
162 UTIL_THROW(
"Incorrect assignment of atoms_ in molecule");
164 if (mPtr->
id() != im) {
167 if (mPtr->speciesPtr_ !=
this) {
168 UTIL_THROW(
"Incorrect species pointer in molecule");
171 if (mPtr->nAtom_ == nAtom_) {
172 for (ia = 0; ia <
nAtom_; ++ia) {
173 aPtr = mPtr->atoms_[ia];
188 if (mPtr->nAtom_ == 0) {
189 for (ia = 0; ia <
nAtom_; ++ia) {
190 if (mPtr->atoms_[ia] != 0) {
191 UTIL_THROW(
"Nonnull atom ptr in empty molecule");
195 UTIL_THROW(
"0 != molecule nAtom != species nAtom");
209 in >> species.capacity_;
210 species.initialize();
222 out << species.capacity_;
int nAtom() const
Get number of atoms per molecule for this Species.
virtual ~Species()
Destructor.
std::istream & operator>>(std::istream &in, MonoclinicBoundary &boundary)
istream extractor for a MonoclinicBoundary.
int nAtom_
Number of atoms per molecule.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.
std::ostream & operator<<(std::ostream &out, const MonoclinicBoundary &boundary)
ostream inserter for an MonoclinicBoundary.
Forward iterator for an Array or a C array.
bool isValid() const
Return true if Species is valid, or throw an Exception.
void setId(int id)
Set integer id for this Species.
int id_
Integer index for this Species.
int id() const
Get integer id of this Species.
int capacity() const
Maximum allowed number of molecules for this Species.
A Species represents a set of chemically similar molecules.