CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SupercellIO_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_SupercellIO_impl
2 #define CASM_SupercellIO_impl
3 
4 #include "casm/clex/PrimClex.hh"
5 #include "casm/clex/Supercell.hh"
11 
12 namespace CASM {
13 
14 namespace ScelIO {
15 
16 // --- template<typename Base> class SupercellCheckBase ---
17 
18 template <typename Base>
20  : Base(name, desc),
21  m_refcell(nullptr),
22  m_last_result(notstd::make_cloneable<result_type>()),
23  m_last_scel(nullptr),
24  m_last_unit(nullptr) {}
25 
27 template <typename Base>
28 bool SupercellCheckBase<Base>::parse_args(const std::string &args) {
29  std::vector<std::string> splt_vec;
30  boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
31  if (args.empty()) {
32  splt_vec.clear();
33  }
34 
35  if (splt_vec.size() != 1) {
36  std::stringstream ss;
37  ss << this->name() << " expected 1 argument. Received " << splt_vec.size()
38  << ": '" << args << "'";
39  throw std::runtime_error(ss.str());
40  }
41 
42  m_refcell_name = args;
43  return true;
44 }
45 
47 template <typename Base>
48 bool SupercellCheckBase<Base>::init(const Supercell &_tmplt) const {
49  auto const &supercell_db = _tmplt.primclex().db<Supercell>();
50  auto it = supercell_db.find(m_refcell_name);
51  if (it == supercell_db.end()) {
52  std::stringstream ss;
53  ss << this->name() << " expected a supercell name. Received '"
54  << m_refcell_name << "': no supercell with this name was found";
55  throw std::runtime_error(ss.str());
56  }
57  m_refcell = &*it;
58  return true;
59 }
60 
62 template <typename Base>
63 std::vector<std::string> SupercellCheckBase<Base>::col_header(
64  const Supercell &_tmplt) const {
65  return std::vector<std::string>{this->name() + "(" + m_refcell_name + ")"};
66 }
67 
74 template <typename Base>
77  const Supercell &unit) const {
78  if (&scel != m_last_scel || &unit != m_last_unit) {
80  scel.lattice(), unit.lattice(), unit.prim().factor_group().begin(),
81  unit.prim().factor_group().end(), unit.crystallography_tol());
82 
83  *m_last_result =
84  std::make_tuple(res.first != unit.prim().factor_group().end(),
85  *res.first, iround(res.second));
86  }
87  return *m_last_result;
88 }
89 
90 template <typename Base>
92  if (m_refcell == nullptr) {
93  std::stringstream ss;
94  ss << this->name() << " expected a supercell name. Received '"
95  << m_refcell_name << "': no supercell with this name was found";
96  throw std::runtime_error(ss.str());
97  }
98  return *m_refcell;
99 }
100 
101 } // namespace ScelIO
102 
103 } // namespace CASM
104 
105 #endif
bool init(const Supercell &_tmplt) const override
Set pointer to ref supercell.
SupercellCheckBase(std::string name, std::string desc)
bool parse_args(const std::string &args) override
Expects arguments of the form 'is_supercell_of(scelname)'.
std::tuple< bool, SymOp, Eigen::MatrixXi > result_type
Definition: SupercellIO.hh:18
const result_type & _evaluate(const Supercell &scel, const Supercell &unit) const
Supercell const & refcell() const
std::vector< std::string > col_header(const Supercell &_tmplt) const override
col_header returns: {'short_name(refcell_name)'}
const MasterSymGroup & factor_group() const
Definition: Structure.cc:107
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
const PrimClex & primclex() const
Use while transitioning Supercell to no longer need a PrimClex const *
Definition: Supercell.cc:150
double crystallography_tol() const
Definition: Supercell.cc:119
const Lattice & lattice() const
The super lattice.
Definition: Supercell.cc:239
const Structure & prim() const
Definition: Supercell.cc:113
Eigen::CwiseUnaryOp< decltype(Local::iround_l< typename Derived::Scalar >), const Derived > iround(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd to Eigen::MatrixXi.
DB::Database< T > & db() const
Definition: PrimClex.cc:302
std::pair< OpIterator, Eigen::Matrix3d > is_equivalent_superlattice(const Object &scel, const Object &unit, OpIterator begin, OpIterator end, double tol)
Definition: SymTools.hh:110
Main CASM namespace.
Definition: APICommand.hh:8
GenericDatumFormatter< std::string, DataObject > name()
Non-std smart pointer classes and functions.
cloneable_ptr< T > make_cloneable(Args &&... args)
make a cloneable_ptr<T> via T(Args... args)
ClexDescription & desc
Definition: settings.cc:138