File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -332,7 +332,8 @@ def append(self, system) :
332
332
# this system is non-converged but the system to append is converged
333
333
self .data = system .data
334
334
return False
335
- assert (system .formula == self .formula )
335
+ if system .uniq_formula != self .uniq_formula :
336
+ raise RuntimeError ('systems with inconsistent formula could not be append: %s v.s. %s' % (self .uniq_formula , system .uniq_formula ))
336
337
if system .data ['atom_names' ] != self .data ['atom_names' ]:
337
338
# allow to append a system with different atom_names order
338
339
system .sort_atom_names ()
@@ -419,6 +420,16 @@ def formula(self):
419
420
return '' .join (["{}{}" .format (symbol ,numb ) for symbol ,numb in
420
421
zip (self .data ['atom_names' ], self .data ['atom_numbs' ])])
421
422
423
+ @property
424
+ def uniq_formula (self ):
425
+ """
426
+ Return the uniq_formula of this system.
427
+ The uniq_formula sort the elements in formula by names.
428
+ Systems with the same uniq_formula can be append together.
429
+ """
430
+ return '' .join (["{}{}" .format (symbol ,numb ) for symbol ,numb in sorted (
431
+ zip (self .data ['atom_names' ], self .data ['atom_numbs' ]))])
432
+
422
433
423
434
def extend (self , systems ):
424
435
"""
Original file line number Diff line number Diff line change
1
+ POSCAR file written by OVITO
2
+ 1
3
+ 10 0.0 0.0
4
+ -0.011409 10 0.0
5
+ 0.1411083 -0.0595569 10
6
+ H O
7
+ 4 3
8
+ d
9
+ .428 .424 .520
10
+ .428 .424 .520
11
+ .230 .628 .113
12
+ .458 .352 .458
13
+ .389 .384 .603
14
+ .137 .626 .150
15
+ .231 .589 .021
Original file line number Diff line number Diff line change 6
6
from comp_sys import CompLabeledSys
7
7
from comp_sys import IsPBC , IsNoPBC
8
8
9
+
10
+ class TestFailedAppend (unittest .TestCase ):
11
+ def test_failed_append (self ):
12
+ sys1 = dpdata .System ('poscars/POSCAR.h2o.md' , fmt = 'vasp/poscar' )
13
+ sys2 = dpdata .System ('poscars/POSCAR.h4o3' , fmt = 'vasp/poscar' )
14
+ with self .assertRaises (Exception ) as c :
15
+ sys1 .append (sys2 )
16
+ self .assertTrue ("systems with inconsistent formula could not be append" in str (c .exception ))
17
+
18
+
9
19
class TestVaspXmlAppend (unittest .TestCase , CompLabeledSys , IsPBC ):
10
20
def setUp (self ) :
11
21
self .places = 6
You can’t perform that action at this time.
0 commit comments