Skip to content

Commit eabec31

Browse files
committed
support nopbc
1 parent 84affb1 commit eabec31

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

dpdata/deepmd/comp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def to_system_data(folder,
4848
data['forces'] = np.concatenate(all_forces, axis = 0)
4949
if len(all_virs) > 0:
5050
data['virials'] = np.concatenate(all_virs, axis = 0)
51+
if os.path.isfile(os.path.join(folder, "nopbc")):
52+
data['nopbc'] = True
5153
return data
5254

5355

@@ -101,5 +103,6 @@ def dump(folder,
101103
np.save(os.path.join(set_folder, 'virial'), virials[set_stt:set_end])
102104
if 'atom_pref' in data:
103105
np.save(os.path.join(set_folder, "atom_pref"), atom_pref[set_stt:set_end])
104-
106+
if data.get("nopbc", False):
107+
os.mknod(os.path.join(folder, "nopbc"))
105108

dpdata/deepmd/raw.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def to_system_data(folder, type_map = None, labels = True) :
4949
if os.path.exists(os.path.join(folder, 'virial.raw')) :
5050
data['virials'] = np.loadtxt(os.path.join(folder, 'virial.raw'))
5151
data['virials'] = np.reshape(data['virials'], [nframes, 3, 3])
52+
if os.path.isfile(os.path.join(folder, "nopbc")):
53+
data['nopbc'] = True
5254
return data
5355
else :
5456
raise RuntimeError('not dir ' + folder)
@@ -67,5 +69,6 @@ def dump (folder, data) :
6769
np.savetxt(os.path.join(folder, 'force.raw'), np.reshape(data['forces'], [nframes, -1]))
6870
if 'virials' in data :
6971
np.savetxt(os.path.join(folder, 'virial.raw'), np.reshape(data['virials'], [nframes, 9]))
70-
72+
if data.get("nopbc", False):
73+
os.mknod(os.path.join(folder, "nopbc"))
7174

dpdata/gaussian/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@ def to_system_data(file_name, md=False):
6969
data['coords'] = np.array(coords_t)
7070
data['orig'] = np.array([0, 0, 0])
7171
data['cells'] = np.array([[[100., 0., 0.], [0., 100., 0.], [0., 0., 100.]] for _ in energy_t])
72+
data['nopbc'] = True
7273
return data

dpdata/system.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ def append(self, system) :
319319
assert(all(eq))
320320
for ii in ['coords', 'cells'] :
321321
self.data[ii] = np.concatenate((self.data[ii], system[ii]), axis = 0)
322+
if self.nopbc and not system.nopbc:
323+
# appended system uses PBC, cancel nopbc
324+
self.data['nopbc'] = False
322325
return True
323326

324327
def sort_atom_names(self, type_map=None):
@@ -726,6 +729,12 @@ def perturb(self,
726729
perturbed_system.append(tmp_system)
727730
return perturbed_system
728731

732+
@property
733+
def nopbc(self):
734+
if self.data.get("nopbc", False):
735+
return True
736+
return False
737+
729738
def get_cell_perturb_matrix(cell_pert_fraction):
730739
if cell_pert_fraction<0:
731740
raise RuntimeError('cell_pert_fraction can not be negative')

tests/comp_sys.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def test_coord(self):
5858
places = self.places,
5959
msg = 'coord[%d][%d][%d] failed' % (ff,ii,jj))
6060

61+
def test_nopbc(self):
62+
self.assertEqual(self.system_1.nopbc, self.system_2.nopbc)
63+
6164

6265
class CompLabeledSys (CompSys) :
6366
def test_energy(self) :

tests/test_gaussian_log.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def test_atom_types(self) :
1818
for ii in range(len(self.atom_types)) :
1919
self.assertEqual(self.system.data['atom_types'][ii], self.atom_types[ii])
2020

21+
def test_nopbc(self):
22+
self.assertEqual(self.nopbc, True)
23+
2124
class TestGaussianLoadLog(unittest.TestCase, TestGaussianLog):
2225
def setUp (self) :
2326
self.system = dpdata.LabeledSystem('gaussian/methane.gaussianlog',

0 commit comments

Comments
 (0)