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
13 changes: 12 additions & 1 deletion dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def append(self, system) :
# this system is non-converged but the system to append is converged
self.data = system.data
return False
assert(system.formula == self.formula)
if system.uniq_formula != self.uniq_formula:
raise RuntimeError('systems with inconsistent formula could not be append: %s v.s. %s' % (self.uniq_formula, system.uniq_formula))
if system.data['atom_names'] != self.data['atom_names']:
# allow to append a system with different atom_names order
system.sort_atom_names()
Expand Down Expand Up @@ -418,6 +419,16 @@ def formula(self):
return ''.join(["{}{}".format(symbol,numb) for symbol,numb in
zip(self.data['atom_names'], self.data['atom_numbs'])])

@property
def uniq_formula(self):
"""
Return the uniq_formula of this system.
The uniq_formula sort the elements in formula by names.
Systems with the same uniq_formula can be append together.
"""
return ''.join(["{}{}".format(symbol,numb) for symbol,numb in sorted(
zip(self.data['atom_names'], self.data['atom_numbs']))])


def extend(self, systems):
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/poscars/POSCAR.h4o3
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
POSCAR file written by OVITO
1
10 0.0 0.0
-0.011409 10 0.0
0.1411083 -0.0595569 10
H O
4 3
d
.428 .424 .520
.428 .424 .520
.230 .628 .113
.458 .352 .458
.389 .384 .603
.137 .626 .150
.231 .589 .021
10 changes: 10 additions & 0 deletions tests/test_system_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
from comp_sys import CompLabeledSys
from comp_sys import IsPBC, IsNoPBC


class TestFailedAppend(unittest.TestCase):
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))


class TestVaspXmlAppend(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp (self) :
self.places = 6
Expand Down