def read_results(self): self.results = {} assert os.path.exists(self.outfile), "%s missing" %self.outfile st = io.read_lammps_md_txt(self.outfile)[0] self.results['energy'] = st.etot self.results['forces'] = st.forces self.results['stress'] = stress_pwtools2ase(st.stress)
def read_results(self): self.results = {} assert os.path.exists(self.outfile), "%s missing" % self.outfile st = io.read_lammps_md_txt(self.outfile)[0] self.results['energy'] = st.etot self.results['forces'] = st.forces self.results['stress'] = stress_pwtools2ase(st.stress)
def test_mix_output(): # Mixing 'run' and 'minimize' commands (and/or using either command # multiple times) causes massive jibber-jabber text output in log.lammps, # which we filter. Check if we get the "thermo_style custom" data between # "Step..." and "Loop..." from each command. # # In this test, we have 3 commands (minimize, run (short MD), minimize), # which are all set to perform 10 steps, so we have 30 in total. Due to # redundant printing by lammps, the result arrays are a bit longer. tgz = 'files/lammps/mix_output.tgz' tgz_path = os.path.dirname(tgz) unpack_path = tgz.replace('.tgz','') common.system("tar -C {0} -xzf {1}".format(tgz_path,tgz)) tr = io.read_lammps_md_txt("{0}/log.lammps".format(unpack_path)) assert tr.nstep == 31 assert tr.coords.shape == (31,4,3) assert tr.stress.shape == (33,3,3) assert tr.temperature.shape == (33,)
def test_mix_output(): # Mixing 'run' and 'minimize' commands (and/or using either command # multiple times) causes massive jibber-jabber text output in log.lammps, # which we filter. Check if we get the "thermo_style custom" data between # "Step..." and "Loop..." from each command. # # In this test, we have 3 commands (minimize, run (short MD), minimize), # which are all set to perform 10 steps, so we have 30 in total. Due to # redundant printing by lammps, the result arrays are a bit longer. tgz = 'files/lammps/mix_output.tgz' tgz_path = os.path.dirname(tgz) unpack_path = tgz.replace('.tgz', '') common.system("tar -C {0} -xzf {1}".format(tgz_path, tgz)) tr = io.read_lammps_md_txt("{0}/log.lammps".format(unpack_path)) assert tr.nstep == 31 assert tr.coords.shape == (31, 4, 3) assert tr.stress.shape == (33, 3, 3) assert tr.temperature.shape == (33, )
def run(tgz, skip=[], atol_map={}): tgz_path = os.path.dirname(tgz) unpack_path = tgz.replace('.tgz', '') common.system("tar -C {0} -xzf {1}".format(tgz_path, tgz)) tr1 = io.read_lammps_md_txt("{0}/log.lammps".format(unpack_path)) tr2 = io.read_lammps_md_dcd("{0}/log.lammps".format(unpack_path)) for name in tr1.attr_lst: if name in skip: continue elif name in atol_map: set_atol(atol_map[name]) else: set_atol() x1 = getattr(tr1, name) x2 = getattr(tr2, name) print(name) tools.assert_all_types_almost_equal(x1, x2) # stress assert (tr1.stress[:, 0, 1] == tr1.stress[:, 1, 0]).all() assert (tr1.stress[:, 0, 2] == tr1.stress[:, 2, 0]).all() assert (tr1.stress[:, 1, 2] == tr1.stress[:, 2, 1]).all()
def run(tgz, skip=[], atol_map={}): tgz_path = os.path.dirname(tgz) unpack_path = tgz.replace('.tgz','') common.system("tar -C {0} -xzf {1}".format(tgz_path,tgz)) tr1 = io.read_lammps_md_txt("{0}/log.lammps".format(unpack_path)) tr2 = io.read_lammps_md_dcd("{0}/log.lammps".format(unpack_path)) for name in tr1.attr_lst: if name in skip: continue elif atol_map.has_key(name): set_atol(atol_map[name]) else: set_atol() x1 = getattr(tr1, name) x2 = getattr(tr2, name) print name tools.assert_all_types_almost_equal(x1, x2) # stress assert (tr1.stress[:,0,1] == tr1.stress[:,1,0]).all() assert (tr1.stress[:,0,2] == tr1.stress[:,2,0]).all() assert (tr1.stress[:,1,2] == tr1.stress[:,2,1]).all()
def test_lammps_calculator(): if not have_ase(): skip("no ASE found, skipping test") elif not have_lmp(): skip("no lammps found, skipping test") else: at = get_atoms_with_calc_lammps() at.rattle(stdev=0.001, seed=int(time.time())) common.makedirs(at.calc.directory) print(common.backtick("cp -v utils/lammps/AlN.tersoff {p}/".format( p=at.calc.directory))) print("scf") forces = at.get_forces() etot = at.get_potential_energy() stress = at.get_stress(voigt=False) # 3x3 st = io.read_lammps_md_txt(at.calc.label + '.out')[0] assert np.allclose(forces, st.forces) assert np.allclose(etot, st.etot) assert np.allclose(st.stress, -stress * constants.eV_by_Ang3_to_GPa, atol=1e-10) print("relax") from ase.optimize import BFGS opt = BFGS(at, maxstep=0.04) opt.run(fmax=0.001, steps=10) coords_frac = parse.arr2d_from_txt(""" 3.3333341909920072e-01 6.6666683819841532e-01 4.4325467247779138e-03 6.6666681184103216e-01 3.3333362368205072e-01 5.0443254824788963e-01 3.3333341909918301e-01 6.6666683819838046e-01 3.8356759709402671e-01 6.6666681184101539e-01 3.3333362368201563e-01 8.8356759861713752e-01 """) assert np.allclose(coords_frac, at.get_scaled_positions(), atol=1e-2) # at least 1 backup files must exist assert os.path.exists(at.calc.infile + '.0') assert os.path.exists(at.calc.outfile + '.0') assert os.path.exists(at.calc.dumpfile + '.0') assert os.path.exists(at.calc.structfile + '.0')
def test_lammps_calculator(): if not have_ase(): skip("no ASE found, skipping test") elif not have_lmp(): skip("no lammps found, skipping test") else: at = get_atoms_with_calc_lammps() at.rattle(stdev=0.001, seed=int(time.time())) common.makedirs(at.calc.directory) print common.backtick("cp -v utils/lammps/AlN.tersoff {p}/".format( p=at.calc.directory)) print "scf" forces = at.get_forces() etot = at.get_potential_energy() stress = at.get_stress(voigt=False) # 3x3 st = io.read_lammps_md_txt(at.calc.label + '.out')[0] assert np.allclose(forces, st.forces) assert np.allclose(etot, st.etot) assert np.allclose(st.stress, -stress * constants.eV_by_Ang3_to_GPa, atol=1e-10) print "relax" from ase.optimize import BFGS opt = BFGS(at, maxstep=0.04) opt.run(fmax=0.001, steps=10) coords_frac = parse.arr2d_from_txt(""" 3.3333341909920072e-01 6.6666683819841532e-01 4.4325467247779138e-03 6.6666681184103216e-01 3.3333362368205072e-01 5.0443254824788963e-01 3.3333341909918301e-01 6.6666683819838046e-01 3.8356759709402671e-01 6.6666681184101539e-01 3.3333362368201563e-01 8.8356759861713752e-01 """) assert np.allclose(coords_frac, at.get_scaled_positions(), atol=1e-2) # at least 1 backup files must exist assert os.path.exists(at.calc.infile + '.0') assert os.path.exists(at.calc.outfile + '.0') assert os.path.exists(at.calc.dumpfile + '.0') assert os.path.exists(at.calc.structfile + '.0')
raise StandardError("only nvt / npt allowed") # create structure file st = crys.Structure(coords_frac=np.array([[0.0]*3, [.5]*3]), cryst_const=np.array([2.85]*3 + [60]*3), symbols=['Al','N']) io.write_lammps('lmp.struct', crys.scell(st,(3,3,3))) # write lmp.in for nvt or npt common.file_write('lmp.in', lmp_in_templ.format(ensemble=ens_txt)) # run lammps common.system("mpirun -np 2 lammps < lmp.in", wait=True) # read trajectory trtxt_orig = io.read_lammps_md_txt('log.lammps') trdcd = io.read_lammps_md_dcd('log.lammps') # plotting plots = mpl.prepare_plots(['coords', 'coords_frac', 'velocity', 'cryst_const', 'cell']) for name,pl in plots.iteritems(): trtxt = trtxt_orig.copy() print name xtxt = getattr(trtxt, name) setattr(trtxt, name, None) xcalc = eval('trtxt.get_%s()' %name) if name == 'cell': sl = np.s_[Ellipsis] func = lambda x: np.reshape(x, (x.shape[0], 9)) elif name in trtxt.attrs_nstep_3d:
raise Exception("only nvt / npt allowed") # create structure file st = crys.Structure(coords_frac=np.array([[0.0]*3, [.5]*3]), cryst_const=np.array([2.85]*3 + [60]*3), symbols=['Al','N']) io.write_lammps('lmp.struct', crys.scell(st,(3,3,3))) # write lmp.in for nvt or npt common.file_write('lmp.in', lmp_in_templ.format(ensemble=ens_txt)) # run lammps common.system("mpirun -np 2 lammps < lmp.in", wait=True) # read trajectory trtxt_orig = io.read_lammps_md_txt('log.lammps') trdcd = io.read_lammps_md_dcd('log.lammps') # plotting plots = mpl.prepare_plots(['coords', 'coords_frac', 'velocity', 'cryst_const', 'cell']) for name,pl in plots.items(): trtxt = trtxt_orig.copy() print(name) xtxt = getattr(trtxt, name) setattr(trtxt, name, None) xcalc = eval('trtxt.get_%s()' %name) if name == 'cell': sl = np.s_[Ellipsis] func = lambda x: np.reshape(x, (x.shape[0], 9)) elif name in trtxt.attrs_nstep_3d:
#!/usr/bin/python # Parse each lammps output and write results/idx/traj.pk from pwtools import sql, io db = sql.SQLiteDB('calc.db', table='calc') for idx in db.get_list1d("select idx from calc"): print idx tr = io.read_lammps_md_txt('calc/%i/log.lammps' %idx) tr.dump('results/%i/traj.pk' %idx)
#!/usr/bin/python # Parse each lammps output and write results/idx/traj.pk from pwtools import sql, io db = sql.SQLiteDB('calc.db', table='calc') for idx in db.get_list1d("select idx from calc"): print(idx) tr = io.read_lammps_md_txt('calc/%i/log.lammps' % idx) tr.dump('results/%i/traj.pk' % idx)