10 #include "casm/external/Eigen/Core"
22 result.
coords.block(0, i * mult, 3, mult) =
28 for (
Index i = 0; i < p.second.cols(); ++i)
29 result.
coords.block(0, i * mult, p.second.rows(), mult) =
30 p.second.col(i).replicate(1, mult);
34 for (
Index b = 0; b < _info.
size(); ++b) {
35 for (
Index g = 0; g < mult; ++g) {
53 Index Nvol = all_lattice_points.size();
61 for (
Index g = 0; g < Nvol; ++g) {
62 Eigen::Vector3d lattice_point_vector =
65 for (
Index m = 0; m < nm; ++m) {
68 for (
Index a = 0; a < na; ++a) {
73 return superstructure;
85 Eigen::Ref<const Eigen::Matrix3i>
const &_T,
88 Index Nvol = all_lattice_points.size();
89 std::vector<Index> basis_idx(_sstruc.
atom_info.
size() * Nvol, -1);
90 for (
Index grid_idx = 0; grid_idx < Nvol; ++grid_idx) {
92 basis_idx[grid_idx + atom_idx * Nvol] = atom_idx;
105 Eigen::VectorXi _mol_occ;
108 _mol_occ.setZero(_struc.
basis().size());
109 for (
Index b = 0; b < _struc.
basis().size(); ++b) {
112 _struc.
basis()[b].occupant_dof()[_mol_occ[b]].name());
121 std::vector<std::vector<Molecule>> _allowed_occupants) {
122 std::map<DoFKey, DoFSet> global_dof;
123 std::map<DoFKey, SiteDoFSet> local_dof;
124 for (
DoFKey const &dof : _all_dofs) {
132 auto const &info = _sstruc.
info(mode);
133 if (_allowed_occupants.empty()) _allowed_occupants.
resize(info.size());
134 for (
Index i = 0; i < info.size(); ++i) {
135 if (_allowed_occupants[i].empty()) {
138 if (_allowed_occupants[i].size() == 1) {
139 std::map<std::string, SpeciesAttribute> attr_map =
140 _allowed_occupants[i][0].attributes();
141 for (
auto it = attr_map.begin(); it != attr_map.end(); ++it) {
142 if (local_dof.count(it->first)) {
144 attr_map.erase(er_it);
148 for (
auto const &prop : info.properties) {
149 if (local_dof.count(prop.first))
continue;
151 if (prop.first ==
"disp")
continue;
154 attr_map.emplace(prop.first,
157 _allowed_occupants[i][0].set_attributes(attr_map);
163 std::vector<Site> tbasis(info.size(),
Site(result.
lattice()));
165 for (
Index i = 0; i < info.size(); ++i) {
166 tbasis[i].cart() = info.cart_coord(i);
167 tbasis[i].set_allowed_occupants(std::move(_allowed_occupants[i]));
168 tbasis[i].set_dofs(local_dof);
193 const std::vector<Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic,
194 Index>> &permute_group) {
196 throw std::runtime_error(
197 "error, the size of the symmetry operations in "
198 "generate_invariant_shuffle_modes do not match");
200 int struc_basis_size = permute_group[0].indices().size();
203 std::vector<Eigen::MatrixXd> displacement_basis;
204 for (
int basis_idx = 0; basis_idx < struc_basis_size; ++basis_idx) {
205 for (
int dir_idx = 0; dir_idx < 3; ++dir_idx) {
207 Eigen::MatrixXd::Zero(3, struc_basis_size);
208 single_shuffle(dir_idx, basis_idx) = 1.0;
209 displacement_basis.push_back(single_shuffle);
212 std::vector<Eigen::VectorXd> displacement_aggregate(
213 displacement_basis.size(),
214 Eigen::VectorXd::Zero(displacement_basis[0].cols() *
215 displacement_basis[0].rows()));
218 for (
int disp_basis_idx = 0; disp_basis_idx < displacement_basis.size();
221 displacement_basis[disp_basis_idx] *
223 displacement_aggregate[disp_basis_idx] +=
225 transformed_disp.data(),
226 transformed_disp.cols() * transformed_disp.rows()));
230 displacement_aggregate.size(), displacement_aggregate[0].size());
231 for (
int disp_basis_idx = 0; disp_basis_idx < displacement_basis.size();
233 displacement_aggregate[disp_basis_idx] =
234 displacement_aggregate[disp_basis_idx] / double(
factor_group.size());
235 sym_disp_basis.row(disp_basis_idx) = displacement_aggregate[disp_basis_idx];
240 sym_disp_basis.transposeInPlace();
241 Eigen::JacobiSVD<Eigen::MatrixXd> svd(
242 sym_disp_basis, Eigen::ComputeThinU | Eigen::ComputeThinV);
243 int matrix_rank = (svd.singularValues().array().abs() >=
CASM::TOL).
sum();
245 svd.matrixV()(Eigen::all, Eigen::seq(0, matrix_rank - 1));
246 std::vector<Eigen::MatrixXd> sym_preserving_modes;
248 for (
int sym_mode_idx = 0; sym_mode_idx < matrix_rank; ++sym_mode_idx) {
249 Eigen::Map<Eigen::MatrixXd> _tmp_mode(
250 sym_preserving_mode_matrix.col(sym_mode_idx).data(), 3,
252 sym_preserving_modes.push_back(_tmp_mode);
254 return sym_preserving_modes;
259 Eigen::Ref<const Eigen::VectorXi>
const &_mol_occ,
264 Index nv = _mol_occ.size() / nb;
266 for (
Index b = 0; b < nb; ++b) {
267 for (
Index v = 0; v < nv; ++v, ++
s) {
268 N_atoms += _reference.
basis()[b].occupant_dof()[_mol_occ[
s]].size();
278 for (
Index b = 0; b < nb; ++b) {
279 for (
Index v = 0; v < nv; ++v, ++
s) {
281 _reference.
basis()[b].occupant_dof()[_mol_occ[
s]];
289 property.first, Eigen::MatrixXd::Zero(dim, N_atoms));
294 for (
Index ma = 0; ma < molref.
size(); ++ma, ++a) {
307 Eigen::MatrixXd::Zero(attr.second.traits().dim(),
312 it->second.col(a) = attr.second.value();
321 it->second.col(a) +=
property.second.col(
s) / double(molref.
size());
323 it->second.col(a) +=
property.second.col(
s);
335 std::vector<std::set<Index>> result;
338 result.push_back({});
339 for (
Index b = 0; b < _prim.
basis().size(); ++b) {
340 if (_prim.
basis()[b].contains(sp)) {
341 result.back().insert(b);
350 std::vector<std::set<Index>> result;
353 result.push_back({});
354 for (
Index b = 0; b < _prim.
basis().size(); ++b) {
355 for (
Molecule const &mol : _prim.
basis()[b].occupant_dof()) {
356 if (mol.contains(sp)) {
357 result.back().insert(b);
std::set< std::string > & s
Specifies traits of (possibly) anisotropic crystal properties.
bool extensive() const
Returns true if type is extensive.
Index dim() const
Conventional dimensionality of this type, returns -1 if always variable.
BasicStructure specifies the lattice and atomic basis of a crystal.
std::vector< Site > & set_basis()
const Lattice & lattice() const
void set_global_dofs(std::map< DoFKey, DoFSet > const &new_dof_map)
Manually set the global DoFs.
const std::vector< Site > & basis() const
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
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
Info & info(SpeciesMode _mode)
Info of specified context (atomic/molecular)
Eigen::Matrix3d lat_column_mat
static Molecule make_atom(std::string const &atom_name)
Return an atomic Molecule with specified name.
Eigen::Vector3d const & cart() const
Const access of Cartesian position of atom.
AtomPosition const & atom(Index i) const
returns i'th atom position
Index size() const
Number of atoms contained Molecule.
std::string const & name() const
Const access of species name.
std::map< std::string, SpeciesAttribute > const & attributes() const
static SimpleStructure::Info _replicate(SimpleStructure::Info const &_info, Index mult)
std::vector< UnitCell > make_lattice_points(const Eigen::Matrix3l &transformation_matrix)
std::vector< Index > superstructure_basis_idx(Eigen::Ref< const Eigen::Matrix3i > const &_T, SimpleStructure const &_sstruc)
Constructs a vector containing the basis index of the ith site in the supercell.
SimpleStructure make_simple_structure(BasicStructure const &_struc)
Construct from decorated structure.
std::vector< std::set< Index > > mol_site_compatibility(SimpleStructure const &sstruc, BasicStructure const &_prim)
Determine which sites of a BasicStructure can host each molecule of a SimpleStructure result[i] is se...
void _atomize(SimpleStructure &_sstruc, Eigen::Ref< const Eigen::VectorXi > const &_mol_occ, BasicStructure const &_reference)
use information in _reference to initialize atom_info from mol_info
std::vector< Eigen::MatrixXd > generate_invariant_shuffle_modes(const std::vector< xtal::SymOp > &factor_group, const std::vector< Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, Index >> &permute_group)
BasicStructure make_basic_structure(SimpleStructure const &_sstruc, std::vector< DoFKey > const &_all_dofs, SimpleStructureTools::SpeciesMode mode, std::vector< std::vector< Molecule >> _allowed_occupants={})
Construct BasicStructure from SimpleStructure.
std::vector< std::set< Index > > atom_site_compatibility(SimpleStructure const &sstruc, BasicStructure const &_prim)
Determine which sites of a BasicStructure can host each atom of a SimpleStructure result[i] is set of...
BasicStructure make_superstructure(const BasicStructure &tiling_unit, const Eigen::Matrix< IntegralType, 3, 3, Options > &transformation_matrix)
Container::value_type sum(const Container &container, typename Container::value_type init_val=0)
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
INDEX_TYPE Index
For long integer indexing:
Struct to encode all information about the crystal basis Info may describe the basis in a atomic cont...
Eigen::MatrixXd coords
(3 x names.size()) matrix of coordinates. coords.col(i) is Cartesian coordinate of site 'i'
std::vector< std::string > names
names[i] is name of species that occupies sites 'i'
Coord cart_coord(Index i)
Access coordinate of site '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...
void resize(Index N)
Resize to hold N sites. All coordinates set to zero, all occupants set to "Va".