def test_get_ase_atoms(): natoms = 10 st = crys.Structure(coords_frac=rand(natoms,3), symbols=['H']*10, cell=rand(3,3)) try: import ase st2 = crys.atoms2struct(crys.struct2atoms(st)) keys = ['natoms', 'coords', 'coords_frac', 'symbols', 'cryst_const', 'cell', 'volume', 'mass'] tools.assert_dict_with_all_types_almost_equal(\ st.__dict__, st2.__dict__, keys=keys, strict=True) # in case the test fails, use this to find out which key failed ## for kk in keys: ## print("testing: %s ..." %kk) ## tools.assert_all_types_almost_equal(st.__dict__[kk], st2.__dict__[kk]) for pbc in [True,False]: at = st.get_ase_atoms(pbc=pbc) assert (at.pbc == np.array([pbc]*3)).all() at = crys.struct2atoms(st, pbc=pbc) assert (at.pbc == np.array([pbc]*3)).all() except ImportError: tools.skip("cannot import ase, skipping test get_ase_atoms()")
def write_input(self, atoms, properties=None, system_changes=None): FileIOCalculator.write_input(self, atoms, properties, system_changes) struct = crys.atoms2struct(atoms) self.cell = common.str_arr(struct.cell) self.kpoints = pwscf.kpoints_str_pwin(kpts2mp(atoms, self.kpts)) if isinstance(self.pp, types.StringType): pseudos = ["%s.%s" %(sym, self.pp) for sym in struct.symbols_unique] else: assert len(self.pp) == struct.ntypat pseudos = [] for sym in struct.symbols_unique: for ppi in self.pp: if ppi.startswith(sym): pseudos.append(ppi) break assert len(pseudos) == struct.ntypat self.atspec = pwscf.atspec_str(symbols=struct.symbols_unique, masses=struct.mass_unique, pseudos=pseudos) self.atpos = pwscf.atpos_str(symbols=struct.symbols, coords=struct.coords_frac) self.natoms = struct.natoms self.ntyp = struct.ntypat if self.backup: for fn in [self.infile, self.outfile]: if os.path.exists(fn): common.backup(fn) common.file_write(self.infile, self.fill_infile_templ())
def test_get_ase_atoms(): natoms = 10 st = crys.Structure(coords_frac=rand(natoms, 3), symbols=['H'] * 10, cell=rand(3, 3)) try: import ase st2 = crys.atoms2struct(crys.struct2atoms(st)) keys = [ 'natoms', 'coords', 'coords_frac', 'symbols', 'cryst_const', 'cell', 'volume', 'mass' ] tools.assert_dict_with_all_types_almost_equal(\ st.__dict__, st2.__dict__, keys=keys, strict=True) # in case the test fails, use this to find out which key failed ## for kk in keys: ## print("testing: %s ..." %kk) ## tools.assert_all_types_almost_equal(st.__dict__[kk], st2.__dict__[kk]) for pbc in [True, False]: at = st.get_ase_atoms(pbc=pbc) assert (at.pbc == np.array([pbc] * 3)).all() at = crys.struct2atoms(st, pbc=pbc) assert (at.pbc == np.array([pbc] * 3)).all() except ImportError: tools.skip("cannot import ase, skipping test get_ase_atoms()")
def write_input(self, atoms, properties=None, system_changes=None): FileIOCalculator.write_input(self, atoms, properties, system_changes) struct = crys.atoms2struct(atoms) self.cell = common.str_arr(struct.cell) self.kpoints = pwscf.kpoints_str_pwin(kpts2mp(atoms, self.kpts)) if isinstance(self.pp, bytes): pseudos = [ "%s.%s" % (sym, self.pp) for sym in struct.symbols_unique ] else: assert len(self.pp) == struct.ntypat pseudos = [] for sym in struct.symbols_unique: for ppi in self.pp: if ppi.startswith(sym): pseudos.append(ppi) break assert len(pseudos) == struct.ntypat self.atspec = pwscf.atspec_str(symbols=struct.symbols_unique, masses=struct.mass_unique, pseudos=pseudos) self.atpos = pwscf.atpos_str(symbols=struct.symbols, coords=struct.coords_frac) self.natoms = struct.natoms self.ntyp = struct.ntypat if self.backup: for fn in [self.infile, self.outfile]: if os.path.exists(fn): common.backup(fn) common.file_write(self.infile, self.fill_infile_templ())
def write_input(self, atoms, properties=None, system_changes=None): FileIOCalculator.write_input(self, atoms, properties, system_changes) if self.backup: for fn in [self.infile, self.outfile, self.dumpfile, self.structfile, self.logfile]: if os.path.exists(fn): common.backup(fn) common.file_write(self.infile, self.fill_infile_templ()) io.write_lammps(self.structfile, crys.atoms2struct(atoms), symbolsbasename=os.path.basename(self.structfile) + \ '.symbols')
def write_input(self, atoms, properties=None, system_changes=None): FileIOCalculator.write_input(self, atoms, properties, system_changes) if self.backup: for fn in [ self.infile, self.outfile, self.dumpfile, self.structfile, self.logfile ]: if os.path.exists(fn): common.backup(fn) common.file_write(self.infile, self.fill_infile_templ()) io.write_lammps(self.structfile, crys.atoms2struct(atoms), symbolsbasename=os.path.basename(self.structfile) + \ '.symbols')