21 poscar_structure.
read(poscar_stream, tol);
22 return poscar_structure;
31 m_global_dof_map(RHS.m_global_dof_map) {
58 throw std::runtime_error(
59 std::string(
"In BasicStructure::dof(), this structure does not contain "
60 "any global DoF's of type " +
77 for (
Index nb = 0; nb <
basis().size(); nb++) {
124 std::vector<double> num_elem;
125 std::vector<std::string> elem_array;
126 bool read_elem =
false;
128 std::stringstream tstrstream;
132 bool SD_flag =
false;
134 if (
title().back() ==
'\r')
135 throw std::runtime_error(std::string(
136 "Structure file is formatted for DOS. Please convert to Unix format. "
137 "(This can be done with the dos2unix command.)"));
142 stream.ignore(100,
'\n');
146 while (ch !=
'\n' && !stream.eof()) {
150 elem_array.push_back(tstr);
152 }
else if (ch ==
' ' || ch ==
'\t') {
155 }
else if (ch >=
'0' && ch <=
'9') {
158 throw std::runtime_error(std::string(
159 "Error attempting to read Structure. Error reading atom names."));
163 if (read_elem ==
true) {
164 stream.ignore(10,
'\n');
170 while (ch !=
'\n' && !stream.eof()) {
171 if (ch >=
'0' && ch <=
'9') {
173 num_elem.push_back(t_int);
176 }
else if (ch ==
' ' || ch ==
'\t') {
180 throw std::runtime_error(std::string(
181 "Error in line 6 of structure input file. Line 6 of structure input "
182 "file should contain the number of sites."));
191 while (ch ==
' ' || ch ==
'\t') {
195 if (ch ==
'S' || ch ==
's') {
197 stream.ignore(1000,
'\n');
198 while (ch ==
' ' || ch ==
'\t') {
204 if (ch ==
'D' || ch ==
'd') {
206 }
else if (ch ==
'C' || ch ==
'c') {
208 }
else if (!SD_flag) {
209 throw std::runtime_error(std::string(
210 "Error in line 7 of structure input file. Line 7 of structure input "
211 "file should specify Direct, Cartesian, or Selective Dynamics."));
212 }
else if (SD_flag) {
213 throw std::runtime_error(
214 std::string(
"Error in line 8 of structure input file. Line 8 of "
215 "structure input file should specify Direct or Cartesian "
216 "when Selective Dynamics is on."));
219 stream.ignore(1000,
'\n');
221 if (
basis().size() != 0) {
222 std::cerr <<
"The structure is going to be overwritten." << std::endl;
230 for (i = 0; i < num_sites; i++) {
233 sum_elem += num_elem[j];
236 tsite.
read(stream, elem_array[j], SD_flag);
242 for (i = 0; i < num_sites; i++) {
243 tsite.
read(stream, SD_flag);
244 if ((stream.rdstate() & std::ifstream::failbit) != 0) {
245 std::cerr <<
"Error reading site " << i + 1
246 <<
" from structure input file." << std::endl;
256 std::istringstream tmp_stream(
s);
257 Eigen::Vector3d coord;
259 if (tmp_stream.good()) {
260 throw std::runtime_error(
261 std::string(
"ERROR: too many sites listed in structure input file."));
270 stream <<
basis().size() <<
'\n';
271 stream <<
title() <<
'\n';
274 stream.flags(std::ios::showpoint | std::ios::fixed | std::ios::right);
275 stream <<
" a b c" <<
'\n';
278 std::string site_label =
basis()[i].allowed_occupants().size() == 1
279 ?
basis()[i].allowed_occupants()[0]
281 stream << std::setw(2) << site_label <<
" ";
283 stream << std::setw(12) <<
basis()[i].frac().transpose() <<
'\n';
285 stream << std::setw(12) <<
basis()[i].cart() <<
'\n';
325 if (dof.second.traits().time_reversal_active())
return true;
327 if (site.time_reversal_active())
return true;
356 std::vector<UnitCellCoord> result;
358 for (
int b = 0; b < _struc.
basis().size(); b++) {
359 Site transformed_basis_site = _op * _struc.
basis()[b];
371 std::set<std::string> result;
376 for (i = 0; i < tstruc_molecule.size(); i++) {
378 for (j = 0; j < tstruc_molecule[i].size(); j++)
379 result.insert(tstruc_molecule[i].atom(j).name());
382 return std::vector<std::string>(result.begin(), result.end());
389 std::vector<Molecule> tstruc_molecule;
393 for (i = 0; i < _struc.
basis().size(); i++) {
395 for (j = 0; j < _struc.
basis()[i].occupant_dof().size(); j++) {
397 if (!
contains(tstruc_molecule, _struc.
basis()[i].occupant_dof()[j])) {
398 tstruc_molecule.push_back(_struc.
basis()[i].occupant_dof()[j]);
403 return tstruc_molecule;
413 std::vector<std::string> struc_mol_name;
414 for (
int i = 0; i < struc_mol.size(); i++) {
415 struc_mol_name.push_back(struc_mol[i].
name());
418 return struc_mol_name;
425 using IPair = std::pair<Index, Index>;
426 std::map<std::string, std::vector<Molecule> > name_map;
427 std::map<std::string, IPair> imap;
429 std::vector<std::vector<std::string> > result(_struc.
basis().size());
430 for (
Index b = 0; b < _struc.
basis().size(); ++b) {
431 for (
Index j = 0; j < _struc.
basis()[b].occupant_dof().size(); ++j) {
433 result[b].push_back(mol.
name());
434 auto it = name_map.find(mol.
name());
435 if (it == name_map.end()) {
436 name_map[mol.
name()].push_back(mol);
437 imap[mol.
name()] = {b, j};
440 if (i == it->second.size()) {
441 it->second.push_back(mol);
443 auto inds = imap[mol.
name()];
444 result[inds.first][inds.second] +=
".1";
458 std::vector<std::vector<std::string> > result(_struc.
basis().size());
460 for (
Index b = 0; b < _struc.
basis().size(); ++b)
461 result[b] = _struc.
basis()[b].allowed_occupants();
469 std::set<std::string> tresult;
471 for (
Site const &site : _struc.
basis()) {
472 auto sitetypes = site.dof_types();
473 tresult.insert(sitetypes.begin(), sitetypes.end());
474 if (site.occupant_dof().size() > 1) {
475 tresult.insert(
"occ");
478 return std::vector<std::string>(tresult.begin(), tresult.end());
482 std::set<std::string> tresult;
484 for (
Site const &site : _struc.
basis()) {
485 auto sitetypes = site.dof_types();
486 tresult.insert(sitetypes.begin(), sitetypes.end());
488 return std::vector<std::string>(tresult.begin(), tresult.end());
492 std::vector<std::string> result;
493 for (
auto const &dof : _struc.
global_dofs()) result.push_back(dof.first);
498 std::vector<std::string> result;
500 result.push_back(global_dof_name);
502 result.push_back(local_dof_name);
507 std::map<DoFKey, Index> result;
515 std::map<DoFKey, Index> result;
517 result[type.first] = type.second.dim();
523 for (
Site const &site : _struc.
basis()) {
524 if (site.has_dof(_name)) result =
max(result, site.dof(_name).dim());
532 return other.find(
"strain") != std::string::npos;
540 return other.find(
"strain") != std::string::npos;
543 throw std::runtime_error(
544 "Error in get_strain_dof_key: Structure does not have strain DoF.");
550 auto pos = strain_dof_key.find(
"strain");
551 if (pos != std::string::npos) {
552 return strain_dof_key.substr(0, pos);
554 std::stringstream msg;
555 msg <<
"Error in get_strain_metric: Failed to get metric name from '"
556 << strain_dof_key <<
"'.";
557 throw std::runtime_error(msg.str());
std::set< std::string > & s
BasicStructure specifies the lattice and atomic basis of a crystal.
void set_lattice(const Lattice &lattice, COORD_TYPE mode)
BasicStructure & operator+=(const Coordinate &shift)
Translates all atoms in cell.
BasicStructure & operator-=(const Coordinate &shift)
Index max_possible_vacancies() const
Counts sites that allow vacancies.
std::map< DoFKey, DoFSet > const & global_dofs() const
static BasicStructure from_poscar_stream(std::istream &poscar_stream, double tol=TOL)
std::vector< Site > & set_basis()
const std::string & title() const
std::string m_title
User-specified name of this Structure.
std::vector< Site > m_basis
Lattice vectors that specifies periodicity of the crystal.
void read(std::istream &stream, double tol=TOL)
void set_title(std::string const &_title)
Set the title of the structure.
void print_xyz(std::ostream &stream, bool frac=false) const
Output other formats.
void within()
Translate all basis sites so that they are inside the unit cell.
const Lattice & lattice() const
void push_back(Site const &_site, COORD_TYPE mode=CART)
Manually set the basis sites.
DoFSet const & global_dof(std::string const &dof_type) const
std::map< DoFKey, DoFSet > m_global_dof_map
continuous global degrees of freedom
bool is_time_reversal_active() const
Returns true if structure has attributes affected by time reversal.
const std::vector< Site > & basis() const
BasicStructure & operator=(const BasicStructure &RHS)
COORD_MODE specifies the current coordinate mode (Fractional or Cartesian)
void set(const COORD_TYPE new_mode)
Represents cartesian and fractional coordinates.
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
void set_tol(double _tol)
void read(std::istream &stream)
Class representing a Molecule.
void read(std::istream &stream, bool SD_is_on=false)
static UnitCellCoord from_coordinate(const PrimType &, const Coordinate &coord, double tol)
std::string to_string(ENUM val)
Return string representation of enum class.
std::string const & name() const
Designated name of Molecule (may be unrelated to constituent species)
std::vector< DoFKey > all_local_dof_types(BasicStructure const &_struc)
std::vector< Molecule > struc_molecule(BasicStructure const &_struc)
Returns an Array of each possible Molecule in this Structure.
std::vector< DoFKey > all_dof_types(BasicStructure const &_struc)
std::vector< std::vector< std::string > > allowed_molecule_names(BasicStructure const &_struc)
Returns a vector with a list of allowed molecule names at each site.
bool has_strain_dof(BasicStructure const &structure)
std::vector< std::string > struc_species(BasicStructure const &_struc)
Returns an Array of each possible AtomSpecie in this Structure.
std::vector< std::vector< std::string > > allowed_molecule_unique_names(BasicStructure const &_struc)
Returns an Array of each possible Molecule in this Structure.
std::vector< DoFKey > continuous_local_dof_types(BasicStructure const &_struc)
std::vector< UnitCellCoord > symop_site_map(SymOp const &_op, BasicStructure const &_struc)
To which site a SymOp transforms each basis site.
DoFKey get_strain_dof_key(BasicStructure const &structure)
std::vector< std::string > struc_molecule_name(BasicStructure const &_struc)
Returns an Array of each possible Molecule in this Structure.
Index local_dof_dim(DoFKey const &_name, BasicStructure const &_struc)
std::map< DoFKey, Index > local_dof_dims(BasicStructure const &_struc)
std::vector< DoFKey > global_dof_types(BasicStructure const &_struc)
std::map< DoFKey, Index > global_dof_dims(BasicStructure const &_struc)
std::string get_strain_metric(DoFKey strain_dof_key)
ConfigIO::GenericConfigFormatter< jsonParser > structure()
GenericVectorXdScelFormatter lattice()
Index find_index(const std::vector< Site > &basis, const Site &test_site, double tol)
GenericDatumFormatter< std::string, DataObject > name()
Index find_index_if(Iterator begin, Iterator end, UnaryPredicate p)
Equivalent to std::distance(begin, std::find_if(begin, end, p))
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value)
INDEX_TYPE Index
For long integer indexing:
T max(const T &A, const T &B)