def setUp(self): tmp_system = dpdata.System() tmp_system.from_vasp_poscar(os.path.join('poscars', 'POSCAR.oh.d')) # tmp_system.from_lammps_lmp(os.path.join('poscars', 'conf.lmp'), type_map = ['O', 'H']) tmp_system.to_vasp_poscar('tmp.POSCAR') self.system = dpdata.System() self.system.from_vasp_poscar('tmp.POSCAR')
def test_failed_append(self): sys1 = dpdata.System('poscars/POSCAR.h2o.md', fmt='vasp/poscar') sys2 = dpdata.System('poscars/POSCAR.h4o3', fmt='vasp/poscar') with self.assertRaises(Exception) as c: sys1.append(sys2) self.assertTrue("systems with inconsistent formula could not be append" in str(c.exception))
def setUp(self): self.system_1 = dpdata.System('amber/sqm.out', fmt='sqm/out') self.system_1.to('deepmd/npy', 'tmp.deepmd.npy') self.system_2 = dpdata.System('tmp.deepmd.npy', fmt='deepmd/npy') self.places = 5 self.e_places = 4 self.f_places = 6 self.v_places = 6
def setUp(self, random_mock): random_mock.rand = ConstGenerator().rand random_mock.randn = ConstGenerator().randn system_1_origin = dpdata.System('poscars/POSCAR.SiC', fmt='vasp/poscar') self.system_1 = system_1_origin.perturb(1, 0.05, 0.6, 'const') self.system_2 = dpdata.System('poscars/POSCAR.SiC.const', fmt='vasp/poscar') self.places = 6
def setUp(self): self.system_1 = dpdata.System('poscars/POSCAR.SiC', fmt='vasp/poscar') self.system_1.replicate(( 1, 2, 3, )) self.system_2 = dpdata.System('poscars/POSCAR.SiC', fmt='vasp/poscar') self.places = 6
def test_dump_vasp_type_map(self): system0 = dpdata.System(os.path.join('poscars', 'POSCAR.oh.d'), fmt='vasp/poscar', type_map=['H', 'O']) system0.to_vasp_poscar('POSCAR.tmp.1') system1 = dpdata.System(os.path.join('poscars', 'POSCAR.oh.d'), fmt='vasp/poscar', type_map=['C', 'H', 'A', 'O', 'B']) system1.to_vasp_poscar('POSCAR.tmp.2') myfilecmp(self, 'POSCAR.tmp.1', 'POSCAR.tmp.2')
def setUp(self, random_mock): random_mock.choice = ConstGenerator().choice self.system_1 = dpdata.System('poscars/POSCAR.P42nmc', fmt='vasp/poscar') self.system_1.replace('Hf', 'Zr', 8) # print(self.system_1.data) self.system_2 = dpdata.System('poscars/POSCAR.P42nmc.replace', fmt='vasp/poscar') # print(self.system_2.data) self.places = 6
def setUp(self): self.system_1 = dpdata.System('poscars/POSCAR.h2o.md', fmt='vasp/poscar') self.system_1.to_deepmd_raw('tmp.deepmd') self.system_2 = dpdata.System('tmp.deepmd', fmt='deepmd/raw', type_map=['O', 'H']) self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def setUp(self): system_1 = dpdata.System() system_1.from_lammps_lmp(os.path.join('poscars', 'conf.lmp'), type_map=['O', 'H']) write('tmp.POSCAR', system_1.to_ase_structure()[0], vasp5=True) self.system_1 = system_1 self.system_2 = dpdata.System('tmp.POSCAR') self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def setUp(self): system_1 = dpdata.System() system_1.from_lammps_lmp(os.path.join('poscars', 'conf.lmp'), type_map=['O', 'H']) system_1.to_pymatgen_structure()[0].to('poscar', 'tmp.POSCAR') self.system_1 = system_1 self.system_2 = dpdata.System('tmp.POSCAR') self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def setUp(self): sys0 = dpdata.System('poscars/POSCAR.oh.d', fmt = 'vasp/poscar') sys0.data['atom_names'] = ['A', 'H', 'B', 'O', 'D'] sys0.data['atom_numbs'] = [ 0, 1, 0, 1, 0] sys0.data['atom_types'] = np.array([ 3, 1], dtype = int) sys1 = dpdata.System('poscars/POSCAR.oh.d', fmt = 'vasp/poscar', type_map = ['A', 'H', 'B', 'O', 'D']) self.system_1 = sys0 self.system_2 = sys1 self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def setUp(self): self.system_1 = dpdata.System('poscars/POSCAR.h2o.md', fmt='vasp/poscar') self.system_1.to_deepmd_npy('tmp.deepmd.npy', prec=np.float64, set_size=2) self.system_2 = dpdata.System('tmp.deepmd.npy', fmt='deepmd/npy', type_map=['O', 'H']) self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def setUp(self): self.system_1 = dpdata.System(os.path.join('poscars', 'conf.5.dump'), type_map=['O', 'H'], begin=1, step=2) self.system_2 = dpdata.System(os.path.join('poscars', 'conf.5.dump'), type_map = ['O', 'H'], begin = 0, step = 1) \ .sub_system(np.arange(1,5,2)) self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 4
def setUp(self): self.system_1 = dpdata.System(os.path.join('pwscf.traj', 'traj6'), fmt = 'pwscf/traj', begin = 1, step = 2) self.system_2 = dpdata.System(os.path.join('pwscf.traj', 'traj6'), fmt = 'pwscf/traj', begin = 0, step = 1) \ .sub_system(np.arange(1,6,2)) self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 4
def setUp(self): self.system = dpdata.System() self.system.from_lammps_lmp(os.path.join('poscars', 'conf.waterion.lmp'), type_map = ['O', 'H']) self.bonds = dpdata.md.water.compute_bonds(self.system.data['cells'][0], self.system.data['coords'][0], self.system.data['atom_types'])
def test_read_file(self): system = dpdata.System('gromacs/multi_frames.gro', type_map=['H', 'O']) self.assertTrue('H' in system['atom_names']) self.assertTrue('O' in system['atom_names']) self.assertEqual(system['atom_numbs'], [6, 3]) for cc, ii in enumerate([1, 0, 0, 1, 0, 0, 1, 0, 0]): self.assertEqual(system['atom_types'][cc], ii) self.assertEqual(len(system['cells']), 2) self.assertEqual(len(system['coords']), 2) for ii in range(3): for jj in range(3): if ii != jj: self.assertAlmostEqual(system['cells'][0][ii][jj], 0) # frame no.1 self.assertAlmostEqual(system['cells'][1][ii][jj], 0) # frame no.2 # frame no.1 self.assertAlmostEqual(system['cells'][0][0][0], 7.822838765564372) self.assertAlmostEqual(system['cells'][0][1][1], 7.353572647182051) self.assertAlmostEqual(system['cells'][0][2][2], 9.036518515423753) self.assertAlmostEqual(system['coords'][0][8][0], 7.43) self.assertAlmostEqual(system['coords'][0][8][1], 5.12) self.assertAlmostEqual(system['coords'][0][8][2], 3.36) # frame no.2 self.assertAlmostEqual(system['cells'][1][0][0], 7.822838765564372) self.assertAlmostEqual(system['cells'][1][1][1], 7.353572647182051) self.assertAlmostEqual(system['cells'][1][2][2], 9.036518515423753) self.assertAlmostEqual(system['coords'][1][8][0], 7.43) self.assertAlmostEqual(system['coords'][1][8][1], 5.12) self.assertAlmostEqual(system['coords'][1][8][2], 3.36)
def setUp(self): self.dir_name = 'tmp.deepmd.npy.nol' natoms = 3 atom_names = ['O', 'H'] atom_numbs = [1, 2] atom_types = np.array([0, 1, 1], dtype=np.int32) nframes = 11 half_n = 6 idx = [range(0, half_n), range(half_n, nframes)] os.makedirs(self.dir_name, exist_ok=True) os.makedirs(os.path.join(self.dir_name, 'set.000'), exist_ok=True) os.makedirs(os.path.join(self.dir_name, 'set.001'), exist_ok=True) np.savetxt(os.path.join(self.dir_name, 'type.raw'), atom_types, fmt='%d') coords = np.random.random([nframes, natoms, 3]) cells = np.random.random([nframes, 3, 3]) np.save(os.path.join(self.dir_name, 'set.000', 'coord.npy'), coords[idx[0]]) np.save(os.path.join(self.dir_name, 'set.000', 'box.npy'), cells[idx[0]]) np.save(os.path.join(self.dir_name, 'set.001', 'coord.npy'), coords[idx[1]]) np.save(os.path.join(self.dir_name, 'set.001', 'box.npy'), cells[idx[1]]) data = { 'atom_names': atom_names, 'atom_types': atom_types, 'atom_numbs': atom_numbs, 'coords': coords, 'cells': cells, 'orig': np.zeros(3), } self.system_1 = dpdata.System(self.dir_name, fmt='deepmd/npy', type_map=['O', 'H']) self.system_2 = dpdata.System() self.system_2.data = data self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def setUpClass(cls) -> None: sp.check_output([ "dpdata", "poscars/conf.lmp", "--type-map", "O", "H", "-olammps/lmp", "-O", "tmp.lmp", "--no-labeled" ]) cls.system = dpdata.System('tmp.lmp', fmt='lammps/lmp', type_map=['O', 'H'])
def setUp(self): self.places = 6 xml_sys = dpdata.LabeledSystem() xml_sys.from_vasp_xml('poscars/vasprun.h2o.md.xml') # init_sys = dpdata.System() # init_sys.from_vasp_poscar('poscars/POSCAR.h2o.md') finl_sys = dpdata.System() finl_sys.from_vasp_poscar('poscars/CONTCAR.h2o.md') self.system_1 = finl_sys self.system_2 = xml_sys.sub_system([-1])
def test_no_format_atom_name(self): system = dpdata.System("gromacs/case_for_format_atom_name.gro", fmt='gromacs/gro', format_atom_name=False) atoms = [ 'CL1', 'H6', 'C4', 'C3', 'C6', 'C11', 'H10', 'C2', 'N3', 'C14', 'H7', 'H8', 'C13', 'H2', 'H1', 'H4', 'O2', 'H9', 'O1', 'N2', 'C9', 'H3', 'C5', 'H11', 'N1', 'C7', 'C10', 'CL2', 'H5', 'C1', 'C8', 'C12' ] for at in atoms: self.assertTrue(at in system['atom_names'])
def test_to_xyz(self): with tempfile.NamedTemporaryFile('r') as f_xyz: dpdata.System(data={ "atom_names": ["C", "O"], "atom_numbs": [1, 1], "atom_types": np.array([0, 1]), "coords": np.arange(6).reshape((1,2,3)), "cells": np.zeros((1,3,3)), "orig": np.zeros(3), }).to("xyz", f_xyz.name) xyz0 = f_xyz.read().strip() xyz1 = "2\n\nC 0.000000 1.000000 2.000000\nO 3.000000 4.000000 5.000000" self.assertEqual(xyz0, xyz1)
def setUp(self): self.system = dpdata.System() self.system.data['atom_types'] = np.array([0, 1]) self.system.data['atom_names'] = ['O', 'H'] nframes = 10 cell_size = 5 self.system.data['cells'] = np.tile(cell_size * np.eye(3), (nframes, 1, 1)) self.system.data['coords'] = np.zeros([nframes, 2, 3]) for ff in range(nframes): self.system.data['coords'][ff][0] = 1.0 * ff * np.array([1, 0, 0]) self.system.data['coords'][ff][1] = 2.0 * ff * np.array([1, 0, 0]) self.system.data['coords'] = self.system.data['coords'] % cell_size
def setUp(self): self.dir_name = 'tmp.deepmd.nol' natoms = 3 atom_names = ['O', 'H'] atom_numbs = [1, 2] atom_types = np.array([0, 1, 1], dtype=np.int32) nframes = 11 os.makedirs(self.dir_name, exist_ok=True) np.savetxt(os.path.join(self.dir_name, 'type.raw'), atom_types, fmt='%d') coords = np.random.random([nframes, natoms, 3]) cells = np.random.random([nframes, 3, 3]) np.savetxt(os.path.join(self.dir_name, '', 'coord.raw'), np.reshape(coords, [nframes, -1])) np.savetxt(os.path.join(self.dir_name, '', 'box.raw'), np.reshape(cells, [nframes, -1])) data = { 'atom_names': atom_names, 'atom_types': atom_types, 'atom_numbs': atom_numbs, 'coords': coords, 'cells': cells, 'orig': np.zeros(3), } self.system_1 = dpdata.System(self.dir_name, fmt='deepmd/raw', type_map=['O', 'H']) self.system_2 = dpdata.System() self.system_2.data = data self.places = 6 self.e_places = 6 self.f_places = 6 self.v_places = 6
def test_poscar_to_molecule(self): tmp_system = dpdata.System() tmp_system.from_vasp_poscar(os.path.join('pymatgen', 'mol2.vasp')) natoms = len(tmp_system['coords'][0]) tmpcoord = tmp_system['coords'][0] cog = np.average(tmpcoord, axis=0) dist = tmpcoord - np.tile(cog, [natoms, 1]) max_dist_0 = np.max(np.linalg.norm(dist, axis=1)) mols = tmp_system.to("pymatgen/molecule") cog = np.average(mols[-1].cart_coords, axis=0) dist = mols[-1].cart_coords - np.tile(cog, [natoms, 1]) max_dist_1 = np.max(np.linalg.norm(dist, axis=1)) self.assertAlmostEqual(max_dist_0, max_dist_1)
def test_pbc(self): nframes = 10 natoms = 20 data = {} data['coords'] = np.random.random([nframes, natoms, 3]) + [5, 5, 5] data['cells'] = np.tile(10 * np.eye(3), [nframes, 1, 1]) data['cells'] += np.random.random([nframes, 3, 3]) shift = 20 * (np.random.random([nframes, natoms, 3]) - 0.5) shift = shift.astype(int) bk_coord = np.copy(data['coords']) data['coords'] += np.matmul(shift, data['cells']) sys = dpdata.System() sys.data = data sys.apply_pbc() for ii in range(nframes): for jj in range(natoms): for dd in range(3): self.assertAlmostEqual(sys['coords'][ii][jj][dd], bk_coord[ii][jj][dd], msg='coord[%d][%d][%d] failed' % (ii, jj, dd))
def test_read_file_tri(self): system = dpdata.System('gromacs/1h.tri.gro') self.assertEqual(system['atom_names'], ['H', 'O']) self.assertEqual(system['atom_numbs'], [6, 3]) for cc,ii in enumerate([1, 0, 0, 1, 0, 0, 1, 0, 0]): self.assertEqual(system['atom_types'][cc], ii) self.assertEqual(len(system['cells']), 1) self.assertEqual(len(system['coords']), 1) count = 0 for ii in range(3): for jj in range(3): if ii != jj: self.assertAlmostEqual(system['cells'][0][ii][jj], count) count += 1 self.assertAlmostEqual(system['cells'][0][0][0], 7.822838765564372) self.assertAlmostEqual(system['cells'][0][1][1], 7.353572647182051) self.assertAlmostEqual(system['cells'][0][2][2], 9.036518515423753) self.assertAlmostEqual(system['coords'][0][8][0], 7.43) self.assertAlmostEqual(system['coords'][0][8][1], 5.12) self.assertAlmostEqual(system['coords'][0][8][2], 3.36) system.to('vasp/poscar', 'POSCAR')
def test_data_empty(self): data = { 'atom_names': ['A', 'B'], 'atom_numbs': [0, 0], 'atom_types': np.array([], dtype=int), 'orig': np.array([0, 0, 0]), 'cells': np.array([]), 'coords': np.array([]), } sys1 = dpdata.System(data=data) data = { 'atom_names': ['A', 'B'], 'atom_numbs': [0, 0], 'atom_types': np.array([], dtype=int), 'orig': np.array([0, 0, 0]), 'cells': np.array([]), 'coords': np.array([]), 'forces': np.array([]), 'energies': np.array([]), 'virials': np.array([]), } sys2 = dpdata.LabeledSystem(data=data)
def test_remove(self): coords = np.array([[[-1, -1, 2], [-1, -1, -3], [-1, -1, 7]], [[3, -1, 3], [-1, -1, 3], [7, -1, 3]]], dtype=float) cogs = np.average(coords, axis=1) data = { 'atom_names': ['A', 'B'], 'atom_numbs': [1, 2], 'atom_types': np.array([1, 0, 1], dtype=int), 'orig': np.array([0, 0, 0]), 'coords': coords, 'cells': np.random.random([2, 3, 3]), } sys = dpdata.System(data=data) proct = 9.0 mol_size = np.array([5, 4], dtype=float) cell_size = (mol_size + proct) * 2.0 sys.remove_pbc(proct) for ff in range(2): ref = cell_size[ff] * np.eye(3) for ii in range(3): for jj in range(3): self.assertAlmostEqual(sys['cells'][ff][ii][jj], ref[ii][jj], msg='%d %d %d' % (ff, ii, jj)) dists = [] for ii in range(sys.get_natoms()): for jj in range(3): dists.append(np.abs(sys['coords'][ff][ii][jj])) dists.append( np.abs(sys['cells'][ff][jj][jj] - sys['coords'][ff][ii][jj])) self.assertAlmostEqual(np.min(dists), proct)
def setUp(self): tmp_system = dpdata.System(os.path.join('poscars', 'conf.lmp'), type_map=['O', 'H']) tmp_system.to_lammps_lmp('tmp.lmp') self.system = dpdata.System() self.system.from_lammps_lmp('tmp.lmp', type_map=['O', 'H'])
def setUp(self): self.system = dpdata.System() self.system.from_vasp_poscar(os.path.join('poscars', 'POSCAR.oh.c'))