CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Molecule.hh
Go to the documentation of this file.
1 #ifndef MOLECULE_HH
2 #define MOLECULE_HH
3 
4 #include <array>
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 
12 #include "casm/misc/Comparisons.hh"
13 
14 namespace CASM {
15 namespace xtal {
16 class Molecule;
17 
24 //****************************************************
25 
27 class AtomPosition {
28  public:
30  AtomPosition(double _pos1, double _pos2, double _pos3,
31  std::string const &_species)
32  : m_species(_species), m_position(_pos1, _pos2, _pos3) {}
33 
35  AtomPosition(Eigen::Ref<const Eigen::Vector3d> const &_pos,
36  std::string const &_species)
37  : m_species(_species), m_position(_pos) {}
38 
40  std::string const &name() const { return m_species; }
41 
43  Eigen::Vector3d const &cart() const { return m_position; }
44 
45  bool time_reversal_active() const {
46  for (auto const &_attr : attributes()) {
47  if (_attr.second.traits().time_reversal_active()) return true;
48  }
49  return false;
50  }
51 
52  std::map<std::string, SpeciesAttribute> const &attributes() const {
53  return m_attribute_map;
54  }
55 
56  void set_attributes(std::map<std::string, SpeciesAttribute> _attr) {
57  m_attribute_map = std::move(_attr);
58  }
59 
62  bool identical(AtomPosition const &RHS, double _tol) const;
63 
64  private:
66  std::string m_species;
67 
69  Eigen::Vector3d m_position;
70 
71  std::map<std::string, SpeciesAttribute> m_attribute_map;
72 };
73 
74 bool compare_type(AtomPosition const &A, AtomPosition const &B, double tol);
75 //****************************************************
76 
93 class Molecule {
94  public:
96  static Molecule make_atom(std::string const &atom_name);
97 
99  static Molecule make_unknown() { return make_atom("UNKNOWN"); }
100 
102  static Molecule make_vacancy();
103 
106  Molecule(std::string const &_name, std::vector<AtomPosition> _atoms = {},
107  bool _divisible = false)
108  : m_name(_name), m_atoms(std::move(_atoms)), m_divisible(_divisible) {
109  if (m_atoms.empty()) m_atoms.emplace_back(0., 0., 0., m_name);
110  }
111 
113  Index size() const { return m_atoms.size(); }
114 
117  std::string const &name() const { return m_name; }
118 
120  std::vector<AtomPosition> const &atoms() const { return m_atoms; }
121 
123  AtomPosition const &atom(Index i) const { return m_atoms[i]; }
124 
126  bool is_atomic() const;
127 
129  bool is_vacancy() const;
130 
133  bool time_reversal_active() const {
134  for (auto const &_atom : atoms()) {
135  if (_atom.time_reversal_active()) return true;
136  }
137  for (auto const &_attr : attributes()) {
138  if (_attr.second.traits().time_reversal_active()) return true;
139  }
140  return false;
141  }
142 
145  std::map<std::string, SpeciesAttribute> const &attributes() const {
146  return m_attribute_map;
147  }
148 
151  void set_attributes(std::map<std::string, SpeciesAttribute> _attr) {
152  m_attribute_map = std::move(_attr);
153  }
154 
157  void set_atoms(std::vector<AtomPosition> _atoms) {
158  m_atoms = std::move(_atoms);
159  }
160 
164  bool identical(Molecule const &RHS, double _tol) const;
165 
167  bool contains(std::string const &atom_name) const;
168 
169  bool is_divisible() const { return m_divisible; }
170 
171  bool is_indivisible() const { return !m_divisible; }
172 
173  private:
174  std::string m_name;
175  std::vector<AtomPosition> m_atoms;
177 
178  std::map<std::string, SpeciesAttribute> m_attribute_map;
179 };
180 
181 inline bool operator==(Molecule const &A, Molecule const &B) {
182  return A.identical(B, TOL);
183 }
184 
187 inline bool is_vacancy(const std::string &name) {
188  return (name == "VA" || name == "va" || name == "Va");
189 }
190 
192 inline bool is_molecule_name(const Molecule &mol, std::string name) {
193  return mol.name() == name || (mol.is_vacancy() && is_vacancy(name));
194 }
195 
197 } // namespace xtal
198 } // namespace CASM
199 
200 namespace CASM {
201 namespace sym {
202 xtal::AtomPosition &apply(const xtal::SymOp &op,
203  xtal::AtomPosition &mutating_atom_pos);
204 xtal::AtomPosition copy_apply(const xtal::SymOp &op,
205  xtal::AtomPosition atom_pos);
206 
207 template <typename ExternSymOp>
208 xtal::AtomPosition copy_apply(const ExternSymOp &op,
209  xtal::AtomPosition atom_pos) {
211  atom_pos);
212 }
213 
214 xtal::Molecule &apply(const xtal::SymOp &op, xtal::Molecule &mutating_mol);
216 
217 template <typename ExternSymOp>
218 xtal::Molecule copy_apply(const ExternSymOp &op, xtal::Molecule mol) {
220 }
221 } // namespace sym
222 } // namespace CASM
223 
224 #endif
An atomic species associated with a position in space.
Definition: Molecule.hh:27
Class representing a Molecule.
Definition: Molecule.hh:93
void set_attributes(std::map< std::string, SpeciesAttribute > _attr)
Set all constitutent attributes of Molecule overwrites any existing attributes.
Definition: Molecule.hh:151
bool is_indivisible() const
Definition: Molecule.hh:171
bool identical(Molecule const &RHS, double _tol) const
Check equality of two molecules, within specified tolerance. Compares atoms, irrespective of order,...
Definition: Molecule.cc:52
AtomPosition(Eigen::Ref< const Eigen::Vector3d > const &_pos, std::string const &_species)
Construct with vector position and atom name.
Definition: Molecule.hh:35
std::vector< AtomPosition > const & atoms() const
Const access of all contained AtomPositions.
Definition: Molecule.hh:120
bool compare_type(AtomPosition const &A, AtomPosition const &B, double tol)
Definition: Molecule.cc:19
static Molecule make_atom(std::string const &atom_name)
Return an atomic Molecule with specified name.
Definition: Molecule.cc:86
std::vector< AtomPosition > m_atoms
Definition: Molecule.hh:175
std::map< std::string, SpeciesAttribute > m_attribute_map
Definition: Molecule.hh:178
bool is_molecule_name(const Molecule &mol, std::string name)
Return true if Molecule name matches 'name', including Va checks.
Definition: Molecule.hh:192
Molecule(std::string const &_name, std::vector< AtomPosition > _atoms={}, bool _divisible=false)
Construct with designated name, a list of atoms, and whether molecule is chemically divisible.
Definition: Molecule.hh:106
Eigen::Vector3d const & cart() const
Const access of Cartesian position of atom.
Definition: Molecule.hh:43
bool is_vacancy(const std::string &name)
A vacancy is any Specie/Molecule with (name == "VA" || name == "va" || name == "Va")
Definition: Molecule.hh:187
AtomPosition(double _pos1, double _pos2, double _pos3, std::string const &_species)
Construct with x,y,z position coordinates and atom name.
Definition: Molecule.hh:30
bool is_vacancy() const
True if Molecule represents vacancy.
Definition: Molecule.cc:47
static Molecule make_unknown()
Return an atomic Molecule with specified name.
Definition: Molecule.hh:99
void set_atoms(std::vector< AtomPosition > _atoms)
set all constituent atoms of Molecule overwrites any existing atoms
Definition: Molecule.hh:157
bool time_reversal_active() const
True if Molecule contains attributes that are affected by time reversal.
Definition: Molecule.hh:133
bool time_reversal_active() const
Definition: Molecule.hh:45
Eigen::Vector3d m_position
Cartesian position; origin is centered at site.
Definition: Molecule.hh:69
void set_attributes(std::map< std::string, SpeciesAttribute > _attr)
Definition: Molecule.hh:56
bool is_atomic() const
True if Molecule is atom with no other attributes.
Definition: Molecule.cc:36
AtomPosition const & atom(Index i) const
returns i'th atom position
Definition: Molecule.hh:123
std::string const & name() const
Designated name of Molecule (may be unrelated to constituent species)
Definition: Molecule.hh:117
static Molecule make_vacancy()
Return a vacancy Molecule.
Definition: Molecule.cc:90
std::string m_name
Definition: Molecule.hh:174
bool identical(AtomPosition const &RHS, double _tol) const
Comparison with tolerance (max allowed distance between LHS and RHS, in Angstr.)
Definition: Molecule.cc:12
bool operator==(Molecule const &A, Molecule const &B)
Definition: Molecule.hh:181
Index size() const
Number of atoms contained Molecule.
Definition: Molecule.hh:113
bool contains(std::string const &atom_name) const
Returns true of molecule contains atom of specified name.
Definition: Molecule.cc:80
bool is_divisible() const
Definition: Molecule.hh:169
std::string const & name() const
Const access of species name.
Definition: Molecule.hh:40
std::map< std::string, SpeciesAttribute > const & attributes() const
Definition: Molecule.hh:52
std::string m_species
Atomic species.
Definition: Molecule.hh:66
std::map< std::string, SpeciesAttribute > m_attribute_map
Definition: Molecule.hh:71
std::map< std::string, SpeciesAttribute > const & attributes() const
Returns dictionary of all constituent attributes of the Molecule Does not include attributes associat...
Definition: Molecule.hh:145
xtal::Coordinate copy_apply(const xtal::SymOp &op, xtal::Coordinate coord)
Copy and apply SymOp to a Coordinate.
Definition: Coordinate.cc:354
xtal::Coordinate & apply(const xtal::SymOp &op, xtal::Coordinate &coord)
apply SymOp to a Coordinate
Definition: Coordinate.cc:347
Main CASM namespace.
Definition: APICommand.hh:8
const double TOL
Definition: definitions.hh:30
GenericDatumFormatter< std::string, DataObject > name()
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39