CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigDatabaseTools.cc
Go to the documentation of this file.
2 
6 
7 namespace CASM {
8 namespace DB {
9 
10 // /// Returns the canonical form Configuration in the canonical Supercell
11 // ///
12 // /// Note:
13 // /// - The canonical Supercell will be inserted in the "supercell_db"
14 // /// - The canonical Supercell will have a `PrimClex const*` (in the future
15 // this will be
16 // /// deprecated)
17 // Configuration in_canonical_supercell(
18 // Configuration const &configuration,
19 // PrimClex const *primclex,
20 // Database<Supercell> &supercell_db) {
21 //
22 // Supercell const &canon_supercell_of_configuration =
23 // *(make_canonical_and_insert(
24 // primclex,
25 // configuration.supercell().sym_info().supercell_lattice(),
26 // supercell_db).first);
27 //
28 // return fill_supercell(configuration,
29 // canon_supercell_of_configuration).canonical_form();
30 // }
31 //
32 // /// Insert this configuration (in primitive & canonical form) in the database
33 // ///
34 // /// \param primitive_only If true, only the primitive Configuration is
35 // inserted.
36 // ///
37 // /// Note:
38 // /// - By convention, the primitive canonical form of a configuration must
39 // /// always be saved in the config list.
40 // /// - Supercells are inserted in the Supercell database as necessary
41 // /// - If "configuration" is already known to be primitive & canonical, can
42 // use
43 // /// `configuration_db.insert(configuration)` directly.
44 // /// - The canonical Supercell will have a `PrimClex const*` (this will be
45 // deprecated) ConfigInsertResult make_canonical_and_insert(
46 // Configuration const &configuration,
47 // PrimClex const *primclex,
48 // Database<Supercell> &supercell_db,
49 // Database<Configuration> &configuration_db,
50 // bool primitive_only) {
51 //
52 // ConfigInsertResult res;
53 //
54 // Supercell const &canon_supercell_of_configuration = canonical_supercell(
55 // configuration.supercell(),
56 // primclex,
57 // supercell_db);
58 //
59 // Configuration prim_config_in_canon_supercell = in_canonical_supercell(
60 // configuration.primitive(),
61 // primclex,
62 // supercell_db);
63 //
64 // std::tie(res.primitive_it, res.insert_primitive) =
65 // configuration_db.insert(prim_config_in_canon_supercell);
66 //
67 // // if the primitive supercell is the same as the equivalent canonical
68 // supercell if(canon_supercell_of_configuration ==
69 // prim_config_in_canon_supercell.supercell()) {
70 // res.insert_canonical = res.insert_primitive;
71 // res.canonical_it = res.primitive_it;
72 // }
73 // else {
74 // if(primitive_only) {
75 // res.insert_canonical = false;
76 // }
77 // else {
78 // Configuration configuration_in_canon_supercell = fill_supercell(
79 // configuration,
80 // canon_supercell_of_configuration).canonical_form();
81 //
82 // std::tie(res.canonical_it, res.insert_canonical) =
83 // configuration_db.insert(configuration_in_canon_supercell);
84 // }
85 // }
86 // return res;
87 // }
88 
96  Database<Supercell> &supercell_db) {
97  Supercell const &canon_supercell_of_configuration =
99  configuration.supercell().shared_prim(),
100  configuration.supercell().sym_info().supercell_lattice(),
101  supercell_db)
102  .first);
103 
104  return fill_supercell(configuration, canon_supercell_of_configuration)
105  .canonical_form();
106 }
107 
121  Configuration const &configuration, Database<Supercell> &supercell_db,
122  Database<Configuration> &configuration_db, bool primitive_only) {
123  ConfigInsertResult res;
124 
125  Supercell const &canon_supercell_of_configuration =
126  canonical_supercell(configuration.supercell(), supercell_db);
127 
128  Configuration prim_config_in_canon_supercell =
129  in_canonical_supercell(configuration.primitive(), supercell_db);
130 
131  std::tie(res.primitive_it, res.insert_primitive) =
132  configuration_db.insert(prim_config_in_canon_supercell);
133 
134  // if the primitive supercell is the same as the equivalent canonical
135  // supercell
136  if (canon_supercell_of_configuration ==
137  prim_config_in_canon_supercell.supercell()) {
139  res.canonical_it = res.primitive_it;
140  } else {
141  if (primitive_only) {
142  res.insert_canonical = false;
143  } else {
144  Configuration configuration_in_canon_supercell =
145  fill_supercell(configuration, canon_supercell_of_configuration)
146  .canonical_form();
147 
148  std::tie(res.canonical_it, res.insert_canonical) =
149  configuration_db.insert(configuration_in_canon_supercell);
150  }
151  }
152  return res;
153 }
154 } // namespace DB
155 } // namespace CASM
MostDerived canonical_form() const
Configuration primitive() const
Return the primitive Configuration.
const Supercell & supercell() const
Get the Supercell for this Configuration.
virtual std::pair< iterator, bool > insert(const ValueType &obj)=0
Represents a supercell of the primitive parent crystal structure.
Definition: Supercell.hh:51
std::shared_ptr< Structure const > const & shared_prim() const
Definition: Supercell.cc:115
const SupercellSymInfo & sym_info() const
Definition: Supercell.cc:265
const xtal::Lattice & supercell_lattice() const
const reference to supercell lattice
Configuration in_canonical_supercell(Configuration const &configuration, Database< Supercell > &supercell_db)
Returns the canonical form Configuration in the canonical Supercell.
Supercell const & canonical_supercell(Supercell const &supercell, Database< Supercell > &supercell_db)
ConfigInsertResult make_canonical_and_insert(Configuration const &configuration, Database< Supercell > &supercell_db, Database< Configuration > &configuration_db, bool primitive_only)
Insert this configuration (in primitive & canonical form) in the database.
Main CASM namespace.
Definition: APICommand.hh:8
Configuration fill_supercell(Configuration const &motif, std::shared_ptr< Supercell const > const &shared_supercell)
Holds results of Configuration::insert.
bool insert_canonical
True if canonical configuration did not exist before insertion.
iterator primitive_it
Iterator pointing at primitive.
bool insert_primitive
True if primitive did not exist before insertion.
iterator canonical_it
Iterator pointing at canonical, if existing.