def __init__(self, atoms, vectors, cryst_mat, symops, assym_n): self.vectors = vectors self.cryst_mat = cryst_mat self.symops = symops self.assym_n = assym_n self.atoms = atoms self.coord_param_mat = None self.vector_param_mat = None self.cell = self.shift([0, 0, 0]) if self.vectors: self.bordered_cell = [a.real_atom() for a in self.shift([0, 0, 0])] start = Vector(0, 0, 0) for i in range(2): for j in range(2): for k in range(2): self.bordered_cell.append( AtomVector( 'x', start + self.vectors[0] * i + self.vectors[1] * j + self.vectors[2] * k, {})) if self.vectors: self.supercell = self.extended_cell(1) else: self.supercell = self.cell self.neighbours = NeighbourCache(self)
def cartesian_atom(self, atom, cryst_cell=False): vector_basis = np.array([v._data for v in self.vectors]) if (cryst_cell): crysmat = np.array(self.cryst_mat) vector_basis = np.transpose(crysmat).dot(vector_basis) unrel = np.transpose(vector_basis).dot(atom.position()._data) return AtomVector(atom.name(), Vector(unrel), {})
def reflect(c, ax1, ax2): ax_refl = ax1.position().cross(ax2.position()) res = [] for a in c: res.append( AtomVector(a._name, a._vector - a._vector.projection(ax_refl) * 2)) return res
def rotate_to_axis(ax1, ax2, c2): ax_rot = ax1.position().cross(ax2.position()) if rough_equal(ax_rot.length, 0, 0.000001): if rough_equal(ax1.distance(ax2), 0, 0.000001): return c2 else: res = [] for a in c2: res.append(AtomVector(a._name, -a._vector)) return res angle = ax2.position().signed_angle_to(ax1.position(), ax_rot) rot = Orientation.new_axis_angle(ax_rot, angle) res = [] for a in c2: res.append(AtomVector(a._name, rot * a._vector)) return res
def true_relative_atom(self, atom, cryst_cell=False): vector_basis = np.array([v._data for v in self.vectors]) if (cryst_cell): crysmat = np.array(self.cryst_mat) vector_basis = np.transpose(crysmat).dot(vector_basis) rel = np.linalg.inv(np.transpose(vector_basis)).dot( atom.position()._data) return AtomVector(atom.name(), Vector(rel), {})
def rotate_along(ax2, ay1, ay2, c2): ax_rot = ax2.position() r1 = ay1.position() - ay1.position().projection(ax_rot) r2 = ay2.position() - ay2.position().projection(ax_rot) angle = r2.signed_angle_to(r1, ax_rot) rot = Orientation.new_axis_angle(ax_rot, angle) res = [] for a in c2: res.append(AtomVector(a._name, rot * a._vector)) return res
def real_atom(self): return AtomVector(self.name(), self.position(), self.data())
def apply_symop(self, atom, symop): n, inv, rot_mat, translator = symop new_vec = np.array(rot_mat).dot(atom.position()._data) new_vec += np.array(translator) new_vec = self.validate_rel(new_vec) return AtomVector(atom.name(), Vector(new_vec), {})