37 for (
int i = 0; i < _perm.size(); ++i) {
52 template <
typename IterType>
57 IterType best_it = begin;
61 double best_char = op.
matrix().trace();
62 double best_dist = op.
tau().norm();
67 while (begin != end) {
68 t_op = begin->sym_op() * op;
71 if (tdet > best_det) {
73 best_char = tdet * t_op.
matrix().trace();
80 }
else if (tdet == best_det) {
81 tchar = tdet * t_op.
matrix().trace();
85 if (tpdist > best_pdist) {
93 }
else if (tpdist == best_pdist) {
96 if (tdist < best_dist) {
104 }
else if (tchar > best_char) {
133 auto it =
maps.begin();
134 while (it !=
maps.end() &&
143 namespace ConfigMapping {
147 SimpleStructure::SpeciesMode::ATOM) {
151 for (
Molecule const &mol : site.occupant_dof()) {
152 if (_species_mode == SimpleStructure::SpeciesMode::MOL) {
153 result[i].push_back(mol.name());
154 }
else if (_species_mode == SimpleStructure::SpeciesMode::ATOM) {
155 if (mol.size() != 1) {
156 throw std::runtime_error(
157 "ConfigMapping::_allowed_species may only be called on "
158 "structures with single-atom species.");
160 result[i].push_back(mol.atom(0).name());
175 bool transform_cost_mat) {
263 std::pair<ConfigDoF, std::set<std::string> > result(
267 for (
Index b = 0; b < prim.basis().size(); ++b) {
270 for (; j < prim.basis()[b].occupant_dof().size(); ++j) {
271 if (c_info.
names[i] == prim.basis()[b].occupant_dof()[j]) {
272 result.first.occ(i) = j;
276 if (j == prim.structure().basis()[b].occupant_dof().size())
277 throw std::runtime_error(
278 "Attempting to initialize ConfigDoF from SimpleStructure. Species "
280 c_info.
names[i] +
"' is not allowed on sublattice " +
285 for (
auto const &dof : result.first.global_dofs()) {
287 result.first.global_dof(dof.first).from_standard_values(val.first);
288 result.second.insert(val.second.begin(), val.second.end());
291 for (
auto const &dof : result.first.local_dofs()) {
293 result.first.local_dof(dof.first).from_standard_values(val.first);
294 result.second.insert(val.second.begin(), val.second.end());
302 BasicStructure const &_prim, std::vector<xtal::SymOp>
const &_symgroup,
313 std::vector<std::string>
const &_lattice_names) {
314 for (std::string
const &_name : _lattice_names) {
315 auto it =
primclex().template db<Supercell>().find(_name);
316 if (it ==
primclex().
template db<Supercell>().end())
317 throw std::runtime_error(
318 "Could not add mapping lattice constraint " + _name +
319 " because no supercell having that name exists in database.\n");
340 _settings.lattice_weight, _settings.max_vol_change,
341 _settings.options(), _tol > 0. ? _tol : _pclex.crystallography_tol(),
342 _settings.min_va_frac, _settings.max_va_frac),
343 m_settings(_settings) {
350 auto filter = [formatter, &_pclex](
Lattice const &parent,
351 Lattice const &child) ->
bool {
353 check_stream << formatter(
Supercell(&_pclex, parent));
354 return check_stream.
value();
360 for (std::string
const &scel :
settings().forced_lattices) {
363 throw std::runtime_error(
"Cannot restrict mapping to lattice " + scel +
364 ". Superlattice does not exist in project.");
372 std::vector<DoFKey>
const &_hint_dofs)
const {
381 std::vector<DoFKey>
const &_hint_dofs)
const {
387 if (hint_ptr !=
nullptr) {
394 SimpleStructure::SpeciesMode::ATOM),
413 if (!config_maps.empty()) {
414 hint_cost = best_cost = config_maps.rbegin()->cost;
420 std::set<MappingNode> struc_maps;
428 child_struc, lattice_node, k);
429 }
else if (hint_ptr &&
settings().fix_lattice) {
433 if (struc_maps.empty())
434 result.
fail_msg =
"Unable to map structure using same lattice as " +
436 ". Try setting \"fix_lattice\" : false.";
438 }
else if (hint_ptr &&
settings().fix_volume) {
441 child_struc, vol, vol, k, best_cost +
struc_mapper().cost_tol());
442 if (struc_maps.empty())
444 "Unable to map structure assuming volume = " +
std::to_string(vol) +
445 ". Try setting \"fix_volume\" : false.";
449 if (struc_maps.empty())
451 "Imported structure has lattice vectors that are not a perfect "
452 "supercell of PRIM. Try setting \"ideal\" : false.";
456 if (struc_maps.empty())
458 "Unable to map structure to prim. May be incompatible structure, or "
459 "provided settings may be too restrictive.";
464 for (
auto const &map : struc_maps) {
465 std::shared_ptr<Supercell> shared_scel = std::make_shared<Supercell>(
466 &
primclex(), map.lattice_node.parent.superlattice());
469 std::pair<ConfigDoF, std::set<std::string> > tdof =
477 shared_scel->sym_info().permute_begin(),
478 shared_scel->sym_info().permute_end(), map);
488 std::move(resolved_struc),
489 std::move(tdof.second)));
493 if (hint_ptr !=
nullptr) {
498 for (
auto &map : result.
maps) {
499 map.second.hint_cost = hint_cost;
501 if (map.second.config.supercell() != hint_ptr->
supercell()) {
505 if (all_equiv(map.second.config)) {
514 if (all_equiv(it, map.second.config)) {
522 if (occ_equiv(it, map.second.config)) {
Class for comparison of Configurations (with the same Supercell)
ConfigMapper(PrimClex const &_pclex, ConfigMapping::Settings const &_settings, double _tol=-1.)
Construct and initialize a ConfigMapper.
StrucMapper const & struc_mapper() const
ConfigMapperResult import_structure(SimpleStructure const &_struc, Configuration const *hint_ptr=nullptr, std::vector< DoFKey > const &_hint_dofs={ "occ"}) const
imports structure specified by '_struc' into primclex()
const PrimClex & primclex() const
void clear_allowed_lattices()
ConfigMapping::Settings const & settings() const
StrucMapper m_struc_mapper
Maps the supercell volume to a vector of Lattices with that volume.
void add_allowed_lattices(std::vector< std::string > const &_lattice_names)
Configuration & apply_sym(const PermuteIterator &it)
Transform Configuration from PermuteIterator via *this = permute_iterator * *this.
const Lattice & ideal_lattice() const
std::vector< PermuteIterator > point_group() const
Returns the point group that leaves the Configuration unchanged.
const Supercell & supercell() const
Get the Supercell for this Configuration.
virtual std::pair< Eigen::MatrixXd, std::set< std::string > > find_values(std::map< std::string, Eigen::MatrixXd > const &values) const
Retrieve the standard values for a DoF from dictionary of properties from properties....
SupercellSymInfo const & sym_info() const
Reference the SupercellSymInfo containing the operations being pointed at.
PermuteIterator inverse() const
Index permute_ind(Index i) const
PrimClex is the top-level data structure for a CASM project.
PrimStrucMapCalculator(BasicStructure const &_prim, std::vector< xtal::SymOp > const &symgroup={}, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM)
QueryHandler< DataObject > & query_handler()
Structure specifies the lattice and atomic basis of a crystal.
Represents a supercell of the primitive parent crystal structure.
Index volume() const
Return number of primitive cells that fit inside of *this.
const Structure & prim() const
const SupercellSymInfo & sym_info() const
permute_const_iterator permute_end() const
const xtal::Lattice & supercell_lattice() const
const reference to supercell lattice
permute_const_iterator permute_begin() const
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
const matrix_type & matrix() const
Const access of entire cartesian symmetry matrix.
const vector_type & tau() const
Const access of the cartesian translation vector, 'tau'.
BasicStructure specifies the lattice and atomic basis of a crystal.
const std::vector< Site > & basis() const
Represents cartesian and fractional coordinates.
Coordinate_impl::CartCoordinate cart()
Set Cartesian coordinate vector and update fractional coordinate vector.
bool voronoi_within()
Map coordinate into the voronoi cell using a lattice translation.
const vector_type & const_cart() const
user override to force const Access the Cartesian coordinate vector
Class representing a Molecule.
Representation of a crystal of molecular and/or atomic occupants, and any additional properties....
std::map< std::string, Eigen::MatrixXd > properties
Eigen::Matrix3d lat_column_mat
virtual SimpleStructure resolve_setting(MappingNode const &_node, SimpleStructure const &_child_struc) const =0
Creates copy of _child_struc by applying isometry, lattice transformation, translation,...
std::set< MappingNode > map_ideal_struc(const SimpleStructure &child_struc, Index k=1, double max_cost=StrucMapping::big_inf(), double min_cost=-TOL, bool keep_invalid=false) const
k-best mappings of ideal child structure onto parent structure Assumes that child_struc and parent_st...
std::set< MappingNode > map_deformed_struc_impose_lattice(const SimpleStructure &child_struc, const Lattice &imposed_lat, Index k=1, double max_cost=StrucMapping::big_inf(), double min_cost=-TOL, bool keep_invalid=false, SymOpVector const &child_factor_group={SymOp::identity()}) const
k-best mappings of arbitrary child structure onto parent structure imposes simplifying assumption tha...
StrucMapCalculatorInterface const & calculator() const
void add_allowed_lattice(Lattice const &_lat)
specify a superlattice of the parent to be searched during mapping
std::set< MappingNode > map_deformed_struc_impose_lattice_vols(const SimpleStructure &child_struc, Index min_vol, Index max_vol, Index k=1, double max_cost=StrucMapping::big_inf(), double min_cost=-TOL, bool keep_invalid=false, SymOpVector const &child_factor_group={SymOp::identity()}) const
k-best mappings of arbitrary child structure onto parent structure imposes simplifying assumption tha...
std::set< MappingNode > map_deformed_struc(const SimpleStructure &child_struc, Index k=1, double max_cost=StrucMapping::big_inf(), double min_cost=-TOL, bool keep_invalid=false, SymOpVector const &child_factor_group={SymOp::identity()}) const
k-best mappings of arbitrary child structure onto parent structure, without simplifying assumptions I...
void clear_allowed_lattices() const
clear the list of allowed parent superlattices; all superlattices will be generated automatically,...
void set_filter(std::function< bool(Lattice const &, Lattice const &)> _filter_f)
specify to use filtered lattices for mapping. The filter function is of the form bool filter(parent_l...
std::set< MappingNode > map_deformed_struc_impose_lattice_node(const SimpleStructure &child_struc, const LatticeNode &imposed_node, Index k=1, double max_cost=StrucMapping::big_inf(), double min_cost=-TOL, bool keep_invalid=false) const
k-best mappings of arbitrary child structure onto parent structure imposes simplifying assumption tha...
const Lattice & superlattice() const
std::string to_string(ENUM val)
Return string representation of enum class.
Eigen::CwiseUnaryOp< decltype(Local::round_l< typename Derived::Scalar >), const Derived > round(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd.
DB::Database< T > & db() const
ProjectSettings & settings()
xtal::StrucMapping::AllowedSpecies _allowed_species(BasicStructure const &_prim, SimpleStructure::SpeciesMode _species_mode=SimpleStructure::SpeciesMode::ATOM)
Traits const & traits(std::string const &dof_key)
Lookup DoFType::Traits in the global dictionary.
static int _permute_dist(MappingNode::MoleculeMap const &_perm, MappingNode const &_node)
static IterType _strictest_equivalent(IterType begin, IterType end, MappingNode const &_node)
Find symop (as PermuteIterator) that gives the most 'faithful' equivalent mapping This means that (1)...
double big_inf()
Very large value used to denote invalid or impossible mapping.
std::vector< std::vector< std::string > > AllowedSpecies
std::vector< SymOp > make_factor_group(const BasicStructure &struc, double tol=TOL)
std::vector< SymOp > SymOpVector
bool almost_equal(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Check if ClusterInvariants are equal.
IterType begin_next_fg_op(IterType it, IterType end)
xtal::SimpleStructure make_simple_structure(Supercell const &_scel, ConfigDoF const &_dof, std::vector< DoFKey > const &_which_dofs={})
Construct from ConfigDoF _dof belonging to provided Supercell _scel.
MappingNode copy_apply(PermuteIterator const &_it, MappingNode const &_node, bool transform_cost_mat=true)
Reorders the permutation and compounds the spatial isometry (rotation.
std::pair< ConfigDoF, std::set< std::string > > to_configdof(SimpleStructure const &_child_struc, Supercell const &_scel)
Initializes configdof of Supercell '_scel' corresponding to an idealized child structure (encoded by ...
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
ConfigDoF make_configdof(Structure const &prim, Index volume)
Construct zero-valued ConfigDoF.
INDEX_TYPE Index
For long integer indexing:
SymGroup make_point_group(const PermuteIteratorContainer &container, const Lattice &supercell_lattice)
Returns a SymGroup generated from a container of PermuteIterator.
Data structure holding results of ConfigMapper algorithm.
std::string fail_msg
Failure message if could not map to prim.
std::map< MappingNode, Individual > maps
The configurations that the input structure mapped onto.
Index n_optimal(double tol=TOL) const
Struct with optional parameters for Config Mapping Specifies default parameters for all values,...
std::vector< Index > irow
'real' indices of rows in the reduced 'cost_mat' When a site assignment {i,j} is added to forced_on,...
Eigen::Vector3d translation
Mapping translation from child to parent Defined such that translation=parent_coord....
std::set< std::pair< Index, Index > > forced_on
parent->child site assignments that have been forced on at this node for element 'el' such that force...
Class describing the lattice-mapping portion of a particular mapping A general map for child_struc on...
Superlattice parent
PrimGrid for supercell of parent structure The parent structure defines the ideal strain state,...
Eigen::Matrix3d stretch
stretch tensor that takes child superlattice from its de-rotated, deformed state to its ideal,...
Eigen::Matrix3d isometry
cartesian rotation/reflection/rotoreflection that rotates the child superlattice to its de-rotated,...
AssignmentNode atomic_node
Eigen::Vector3d const & translation() const
convenience method to access MappingNode::atomic_node.translation
std::vector< AtomIndexSet > MoleculeMap
std::vector< Index > atom_permutation
Eigen::Matrix3d const & stretch() const
convenience method to access MappingNode::lattice_node.stretch
Eigen::MatrixXd atom_displacement
3xN matrix of displacements for all sites in parent supercell (Va are included, but set to Zero)
std::vector< MoleculeLabel > mol_labels
list of assigned molecule names
Eigen::Matrix3d const & isometry() const
convenience method to access MappingNode::lattice_node.isometry
Struct to encode all information about the crystal basis Info may describe the basis in a atomic cont...
std::vector< std::string > names
names[i] is name of species that occupies sites 'i'
Index size() const
Number of sites is defined as names.size()
std::map< std::string, Eigen::MatrixXd > properties
map of [property name, (m x names.size()) matrix] for all numerical site properties properties are as...