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 @@ -331,7 +331,8 @@ def append(self, system) :
331
331
# this system is non-converged but the system to append is converged
332
332
self .data = system .data
333
333
return False
334
- assert (system .formula == self .formula )
334
+ if system .uniq_formula != self .uniq_formula :
335
+ raise RuntimeError ('systems with inconsistent formula could not be append: %s v.s. %s' % (self .uniq_formula , system .uniq_formula ))
335
336
if system .data ['atom_names' ] != self .data ['atom_names' ]:
336
337
# allow to append a system with different atom_names order
337
338
system .sort_atom_names ()
@@ -418,6 +419,16 @@ def formula(self):
418
419
return '' .join (["{}{}" .format (symbol ,numb ) for symbol ,numb in
419
420
zip (self .data ['atom_names' ], self .data ['atom_numbs' ])])
420
421
422
+ @property
423
+ def uniq_formula (self ):
424
+ """
425
+ Return the uniq_formula of this system.
426
+ The uniq_formula sort the elements in formula by names.
427
+ Systems with the same uniq_formula can be append together.
428
+ """
429
+ return '' .join (["{}{}" .format (symbol ,numb ) for symbol ,numb in sorted (
430
+ zip (self .data ['atom_names' ], self .data ['atom_numbs' ]))])
431
+
421
432
422
433
def extend (self , systems ):
423
434
"""
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