def test_center_coordinates(self): cell = 2.2 * np.identity(3) NaCl = Atoms('NaCl', scaled_positions=[(0, 0, 0), (0.5, 0.5, 0.5)], cell=cell) NaCl.set_repeat([3, 3, 3]) NaCl.positions += [2.2, 2.2, 2.2] NaCl.center_coordinates_in_unit_cell(origin=-0.5) self.assertTrue(-0.5 < np.min(NaCl.scaled_positions)) self.assertTrue(np.max(NaCl.scaled_positions < 0.5)) NaCl.center_coordinates_in_unit_cell(origin=0.) self.assertTrue(0 <= np.min(NaCl.positions)) self.assertTrue(np.max(NaCl.scaled_positions < 1))
def get_structure(self, job_specifier, iteration_step=-1, wrap_atoms=True): """ Gets the structure from a given iteration step of the simulation (MD/ionic relaxation). For static calculations there is only one ionic iteration step Args: job_specifier (str, int): name of the job or job ID iteration_step (int): Step for which the structure is requested wrap_atoms (bool): True if the atoms are to be wrapped back into the unit cell Returns: atomistics.structure.atoms.Atoms object """ job = self.inspect(job_specifier) snapshot = Atoms().from_hdf(job["input"], "structure") if "output" in job.project_hdf5.list_groups() and iteration_step != 0: snapshot.cell = job.get("output/generic/cells")[iteration_step] snapshot.positions = job.get("output/generic/positions")[iteration_step] if "indices" in job.get("output/generic").list_nodes(): snapshot.indices = job.get("output/generic/indices")[iteration_step] if ( "dft" in job["output/generic"].list_groups() and "atom_spins" in job["output/generic/dft"].list_nodes() ): snapshot.set_initial_magnetic_moments( job.get("output/generic/dft/atom_spins")[iteration_step] ) if wrap_atoms: return snapshot.center_coordinates_in_unit_cell() else: return snapshot
def get_structure(self, iteration_step=-1, wrap_atoms=True): """ Gets the structure from a given iteration step of the simulation (MD/ionic relaxation). For static calculations there is only one ionic iteration step Args: iteration_step (int): Step for which the structure is requested wrap_atoms (bool): Returns: atomistics.structure.atoms.Atoms object """ if (self.server.run_mode.interactive or self.server.run_mode.interactive_non_modal): # Warning: We only copy symbols, positions and cell information - no tags. if self.output.indices is not None and len( self.output.indices) != 0: indices = self.output.indices[iteration_step] else: return None if len(self._interactive_species_lst) == 0: el_lst = [el.Abbreviation for el in self.structure.species] else: el_lst = self._interactive_species_lst.tolist() if indices is not None: if wrap_atoms: positions = self.output.positions[iteration_step] else: if len(self.output.unwrapped_positions) > max( [iteration_step, 0]): positions = self.output.unwrapped_positions[ iteration_step] else: positions = ( self.output.positions[iteration_step] + self.output.total_displacements[iteration_step]) atoms = Atoms( symbols=np.array([el_lst[el] for el in indices]), positions=positions, cell=self.output.cells[iteration_step], pbc=self.structure.pbc, ) # Update indicies to match the indicies in the cache. atoms.set_species( [self._periodic_table.element(el) for el in el_lst]) atoms.indices = indices if wrap_atoms: atoms = atoms.center_coordinates_in_unit_cell() return atoms else: return None else: if (self.get("output/generic/cells") is not None and len(self.get("output/generic/cells")) != 0): return super(GenericInteractive, self).get_structure(iteration_step=iteration_step, wrap_atoms=wrap_atoms) else: return None