Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion dpdata/deepmd/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def to_system_data(folder,
data['forces'] = np.concatenate(all_forces, axis = 0)
if len(all_virs) > 0:
data['virials'] = np.concatenate(all_virs, axis = 0)
if os.path.isfile(os.path.join(folder, "nopbc")):
data['nopbc'] = True
return data


Expand Down Expand Up @@ -101,5 +103,10 @@ def dump(folder,
np.save(os.path.join(set_folder, 'virial'), virials[set_stt:set_end])
if 'atom_pref' in data:
np.save(os.path.join(set_folder, "atom_pref"), atom_pref[set_stt:set_end])

try:
os.remove(os.path.join(folder, "nopbc"))
except OSError:
pass
if data.get("nopbc", False):
os.mknod(os.path.join(folder, "nopbc"))

9 changes: 8 additions & 1 deletion dpdata/deepmd/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def to_system_data(folder, type_map = None, labels = True) :
if os.path.exists(os.path.join(folder, 'virial.raw')) :
data['virials'] = np.loadtxt(os.path.join(folder, 'virial.raw'))
data['virials'] = np.reshape(data['virials'], [nframes, 3, 3])
if os.path.isfile(os.path.join(folder, "nopbc")):
data['nopbc'] = True
return data
else :
raise RuntimeError('not dir ' + folder)
Expand All @@ -67,5 +69,10 @@ def dump (folder, data) :
np.savetxt(os.path.join(folder, 'force.raw'), np.reshape(data['forces'], [nframes, -1]))
if 'virials' in data :
np.savetxt(os.path.join(folder, 'virial.raw'), np.reshape(data['virials'], [nframes, 9]))

try:
os.remove(os.path.join(folder, "nopbc"))
except OSError:
pass
if data.get("nopbc", False):
os.mknod(os.path.join(folder, "nopbc"))

1 change: 1 addition & 0 deletions dpdata/gaussian/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ def to_system_data(file_name, md=False):
data['coords'] = np.array(coords_t)
data['orig'] = np.array([0, 0, 0])
data['cells'] = np.array([[[100., 0., 0.], [0., 100., 0.], [0., 0., 100.]] for _ in energy_t])
data['nopbc'] = True
return data
13 changes: 12 additions & 1 deletion dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def sub_system(self, f_idx) :
tmp.data[ii] = self.data[ii]
tmp.data['cells'] = self.data['cells'][f_idx].reshape(-1, 3, 3)
tmp.data['coords'] = self.data['coords'][f_idx].reshape(-1, self.data['coords'].shape[1], 3)
tmp.data['nopbc'] = self.nopbc
return tmp


Expand Down Expand Up @@ -319,6 +320,9 @@ def append(self, system) :
assert(all(eq))
for ii in ['coords', 'cells'] :
self.data[ii] = np.concatenate((self.data[ii], system[ii]), axis = 0)
if self.nopbc and not system.nopbc:
# appended system uses PBC, cancel nopbc
self.data['nopbc'] = False
return True

def sort_atom_names(self, type_map=None):
Expand Down Expand Up @@ -726,6 +730,12 @@ def perturb(self,
perturbed_system.append(tmp_system)
return perturbed_system

@property
def nopbc(self):
if self.data.get("nopbc", False):
return True
return False

def get_cell_perturb_matrix(cell_pert_fraction):
if cell_pert_fraction<0:
raise RuntimeError('cell_pert_fraction can not be negative')
Expand Down Expand Up @@ -1018,6 +1028,7 @@ def from_gaussian_log(self, file_name, md=False):
self.data = dpdata.gaussian.log.to_system_data(file_name, md=md)
except AssertionError:
self.data['energies'], self.data['forces']= [], []
self.data['nopbc'] = True


def from_cp2k_output(self, file_name) :
Expand Down Expand Up @@ -1245,7 +1256,7 @@ def to_deepmd_npy(self, folder, set_size = 5000, prec=np.float32) :
def check_System(data):
keys={'atom_names','atom_numbs','cells','coords','orig','atom_types'}
assert( isinstance(data,dict) )
assert( set(data.keys())==keys )
assert( keys.issubset(set(data.keys())) )
if len(data['coords']) > 0 :
assert( len(data['coords'][0])==len(data['atom_types'])==sum(data['atom_numbs']) )
else :
Expand Down
13 changes: 12 additions & 1 deletion tests/comp_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def test_coord(self):
places = self.places,
msg = 'coord[%d][%d][%d] failed' % (ff,ii,jj))

def test_nopbc(self):
self.assertEqual(self.system_1.nopbc, self.system_2.nopbc)


class CompLabeledSys (CompSys) :
def test_energy(self) :
Expand Down Expand Up @@ -97,4 +100,12 @@ def test_virial(self) :
places = self.v_places,
msg = 'virials[%d][%d][%d] failed' % (ff,ii,jj))


class IsPBC:
def test_is_pbc(self):
self.assertFalse(self.system_1.nopbc)
self.assertFalse(self.system_2.nopbc)

class IsNoPBC:
def test_is_nopbc(self):
self.assertTrue(self.system_1.nopbc)
self.assertTrue(self.system_2.nopbc)
8 changes: 4 additions & 4 deletions tests/test_deepmd_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompLabeledSys, CompSys
from comp_sys import CompLabeledSys, CompSys, IsPBC

class TestDeepmdLoadDumpComp(unittest.TestCase, CompLabeledSys):
class TestDeepmdLoadDumpComp(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.system_1 = dpdata.LabeledSystem('poscars/OUTCAR.h2o.md',
fmt = 'vasp/outcar')
Expand All @@ -25,7 +25,7 @@ def tearDown(self) :
shutil.rmtree('tmp.deepmd.npy')


class TestDeepmdCompNoLabels(unittest.TestCase, CompSys) :
class TestDeepmdCompNoLabels(unittest.TestCase, CompSys, IsPBC) :
def setUp (self) :
self.system_1 = dpdata.System('poscars/POSCAR.h2o.md',
fmt = 'vasp/poscar')
Expand All @@ -45,7 +45,7 @@ def tearDown(self) :
shutil.rmtree('tmp.deepmd.npy')


class TestDeepmdCompNoLabels(unittest.TestCase, CompSys) :
class TestDeepmdCompNoLabels(unittest.TestCase, CompSys, IsPBC) :
def setUp(self) :
self.dir_name = 'tmp.deepmd.npy.nol'
natoms = 3
Expand Down
10 changes: 5 additions & 5 deletions tests/test_deepmd_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompLabeledSys, CompSys
from comp_sys import CompLabeledSys, CompSys, IsPBC

class TestDeepmdLoadRaw(unittest.TestCase, CompLabeledSys):
class TestDeepmdLoadRaw(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.system_1 = dpdata.LabeledSystem('poscars/OUTCAR.h2o.md',
fmt = 'vasp/outcar')
Expand All @@ -17,7 +17,7 @@ def setUp (self) :
self.v_places = 6


class TestDeepmdDumpRaw(unittest.TestCase, CompLabeledSys):
class TestDeepmdDumpRaw(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.system_1 = dpdata.LabeledSystem('poscars/OUTCAR.h2o.md',
fmt = 'vasp/outcar')
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_npy_type_map_enforce (self) :



class TestDeepmdRawNoLabels(unittest.TestCase, CompSys) :
class TestDeepmdRawNoLabels(unittest.TestCase, CompSys, IsPBC) :
def setUp (self) :
self.system_1 = dpdata.System('poscars/POSCAR.h2o.md',
fmt = 'vasp/poscar')
Expand All @@ -149,7 +149,7 @@ def tearDown(self) :
shutil.rmtree('tmp.deepmd')


class TestDeepmdCompNoLabels(unittest.TestCase, CompSys) :
class TestDeepmdCompNoLabels(unittest.TestCase, CompSys, IsPBC) :
def setUp(self) :
self.dir_name = 'tmp.deepmd.nol'
natoms = 3
Expand Down
4 changes: 3 additions & 1 deletion tests/test_gaussian_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompLabeledSys

class TestGaussianLog :
def test_atom_names(self) :
Expand All @@ -18,6 +17,9 @@ def test_atom_types(self) :
for ii in range(len(self.atom_types)) :
self.assertEqual(self.system.data['atom_types'][ii], self.atom_types[ii])

def test_nopbc(self):
self.assertEqual(self.system.nopbc, True)

class TestGaussianLoadLog(unittest.TestCase, TestGaussianLog):
def setUp (self) :
self.system = dpdata.LabeledSystem('gaussian/methane.gaussianlog',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompLabeledSys
from comp_sys import CompLabeledSys, IsPBC

class TestJsonLoad(unittest.TestCase, CompLabeledSys):
class TestJsonLoad(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.system_1 = dpdata.LabeledSystem('poscars/OUTCAR.h2o.md',
fmt = 'vasp/outcar')
Expand All @@ -14,7 +14,7 @@ def setUp (self) :
self.f_places = 6
self.v_places = 4

class TestAsDict(unittest.TestCase, CompLabeledSys):
class TestAsDict(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.system_1 = dpdata.LabeledSystem('poscars/OUTCAR.h2o.md',
fmt = 'vasp/outcar')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lammps_dump_skipload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompSys
from comp_sys import CompSys, IsPBC

class TestLmpDumpSkip(unittest.TestCase, CompSys):
class TestLmpDumpSkip(unittest.TestCase, CompSys, IsPBC):

def setUp(self):
self.system_1 = dpdata.System(os.path.join('poscars', 'conf.5.dump'),
Expand Down
9 changes: 5 additions & 4 deletions tests/test_multisystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from context import dpdata
from comp_sys import CompSys
from comp_sys import CompLabeledSys
from comp_sys import IsNoPBC
from itertools import permutations

class MultiSystems:
Expand All @@ -17,7 +18,7 @@ def test_systems_size(self):
def test_atom_names(self):
self.assertEqual(self.atom_names, self.systems.atom_names)

class TestMultiSystems(unittest.TestCase, CompLabeledSys, MultiSystems):
class TestMultiSystems(unittest.TestCase, CompLabeledSys, MultiSystems, IsNoPBC):
def setUp(self):
self.places = 6
self.e_places = 6
Expand All @@ -39,7 +40,7 @@ def setUp(self):
self.atom_names = ['C', 'H']


class TestMultiSystemsAdd(unittest.TestCase, CompLabeledSys, MultiSystems):
class TestMultiSystemsAdd(unittest.TestCase, CompLabeledSys, MultiSystems, IsNoPBC):
def setUp(self):
self.places = 6
self.e_places = 6
Expand Down Expand Up @@ -76,7 +77,7 @@ def setUp(self):
self.system_sizes = {'C1H4O0':1, 'C0H0O2':1}
self.atom_names = ['C', 'H', 'O']

class TestMultiDeepmdDumpRaw(unittest.TestCase, CompLabeledSys):
class TestMultiDeepmdDumpRaw(unittest.TestCase, CompLabeledSys, IsNoPBC):
def setUp (self) :
self.places = 6
self.e_places = 6
Expand All @@ -94,7 +95,7 @@ def setUp (self) :
self.system_1 = dpdata.LabeledSystem(os.path.join(path, 'C1H3'), fmt='deepmd/raw', type_map = ['C', 'H'])
self.system_2 = system_3

class TestMultiDeepmdDumpComp(unittest.TestCase, CompLabeledSys):
class TestMultiDeepmdDumpComp(unittest.TestCase, CompLabeledSys, IsNoPBC):
def setUp (self) :
self.places = 6
self.e_places = 4
Expand Down
8 changes: 4 additions & 4 deletions tests/test_perturb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompSys
from comp_sys import CompSys, IsPBC

from unittest.mock import Mock
from unittest.mock import patch, MagicMock
Expand Down Expand Up @@ -103,7 +103,7 @@ def get_rand_generator():
yield np.asarray([0.01525907, 0.68387374, 0.39768541, 0.55596047, 0.26557088, 0.60883073])

# %%
class TestPerturbNormal(unittest.TestCase, CompSys):
class TestPerturbNormal(unittest.TestCase, CompSys, IsPBC):
@patch('numpy.random')
def setUp (self, random_mock):
random_mock.rand = NormalGenerator().rand
Expand All @@ -113,7 +113,7 @@ def setUp (self, random_mock):
self.system_2 = dpdata.System('poscars/POSCAR.SiC.normal',fmt='vasp/poscar')
self.places = 6

class TestPerturbUniform(unittest.TestCase, CompSys):
class TestPerturbUniform(unittest.TestCase, CompSys, IsPBC):
@patch('numpy.random')
def setUp (self, random_mock) :
random_mock.rand = UniformGenerator().rand
Expand All @@ -123,7 +123,7 @@ def setUp (self, random_mock) :
self.system_2 = dpdata.System('poscars/POSCAR.SiC.uniform',fmt='vasp/poscar')
self.places = 6

class TestPerturbConst(unittest.TestCase, CompSys):
class TestPerturbConst(unittest.TestCase, CompSys, IsPBC):
@patch('numpy.random')
def setUp (self, random_mock) :
random_mock.rand = ConstGenerator().rand
Expand Down
5 changes: 3 additions & 2 deletions tests/test_qe_cp_traj_skipload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from context import dpdata
from comp_sys import CompSys
from comp_sys import CompLabeledSys
from comp_sys import IsPBC

class TestPWSCFTrajSkip(unittest.TestCase, CompSys):
class TestPWSCFTrajSkip(unittest.TestCase, CompSys, IsPBC):
def setUp(self):
self.system_1 = dpdata.System(os.path.join('qe.traj', 'traj6'),
fmt = 'qe/cp/traj',
Expand All @@ -21,7 +22,7 @@ def setUp(self):
self.f_places = 6
self.v_places = 4

class TestPWSCFLabeledTrajSkip(unittest.TestCase, CompLabeledSys):
class TestPWSCFLabeledTrajSkip(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp(self):
self.system_1 = dpdata.LabeledSystem(os.path.join('qe.traj', 'traj6'),
fmt = 'qe/cp/traj',
Expand Down
14 changes: 7 additions & 7 deletions tests/test_quip_gap_xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import unittest
from context import dpdata
from comp_sys import CompLabeledSys
from comp_sys import CompLabeledSys, IsPBC

class TestQuipGapxyz1(unittest.TestCase, CompLabeledSys):
class TestQuipGapxyz1(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.multi_systems = dpdata.MultiSystems.from_file('xyz/xyz_unittest.xyz','quip/gap/xyz')
self.system_1 = self.multi_systems.systems['B1C9']
Expand All @@ -14,7 +14,7 @@ def setUp (self) :
self.f_places = 6
self.v_places = 4

class TestQuipGapxyz2(unittest.TestCase, CompLabeledSys):
class TestQuipGapxyz2(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.system_temp0 = dpdata.MultiSystems.from_file(file_name='xyz/xyz_unittest.xyz', fmt='quip/gap/xyz')
self.system_1 = self.system_temp0.systems['B5C7'] # .sort_atom_types()
Expand All @@ -27,7 +27,7 @@ def setUp (self) :
self.f_places = 6
self.v_places = 4

class TestQuipGapxyzsort1(unittest.TestCase, CompLabeledSys):
class TestQuipGapxyzsort1(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.multi_systems_1 = dpdata.MultiSystems.from_file('xyz/xyz_unittest.sort.xyz','quip/gap/xyz')
self.system_1 = self.multi_systems_1.systems['B5C7']
Expand All @@ -39,7 +39,7 @@ def setUp (self) :
self.f_places = 6
self.v_places = 4

class TestQuipGapxyzsort2(unittest.TestCase, CompLabeledSys):
class TestQuipGapxyzsort2(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.multi_systems_1 = dpdata.MultiSystems.from_file('xyz/xyz_unittest.sort.xyz','quip/gap/xyz')
self.system_1 = self.multi_systems_1.systems['B1C9']
Expand All @@ -51,7 +51,7 @@ def setUp (self) :
self.f_places = 6
self.v_places = 4

class TestQuipGapxyzfield(unittest.TestCase, CompLabeledSys):
class TestQuipGapxyzfield(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.multi_systems_1 = dpdata.MultiSystems.from_file('xyz/xyz_unittest.field.xyz','quip/gap/xyz')
self.system_1 = self.multi_systems_1.systems['B1C9']
Expand All @@ -63,7 +63,7 @@ def setUp (self) :
self.f_places = 6
self.v_places = 4

class TestQuipGapxyzfield2(unittest.TestCase, CompLabeledSys):
class TestQuipGapxyzfield2(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.multi_systems_1 = dpdata.MultiSystems.from_file('xyz/xyz_unittest.field.xyz','quip/gap/xyz')
self.system_1 = self.multi_systems_1.systems['B5C7']
Expand Down
Loading