Skip to content

Commit 73e9cf9

Browse files
authored
Merge pull request #109 from zezhong-zhang/devel
Sort atom according to the type_map in Multisystem
2 parents 572c004 + eb37843 commit 73e9cf9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

dpdata/system.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ def sort_atom_names(self, type_map=None):
368368
# atom_names must be a subset of type_map
369369
assert (set(self.data['atom_names']).issubset(set(type_map)))
370370
# for the condition that type_map is a proper superset of atom_names
371-
new_atoms = set(type_map) - set(self.data["atom_names"])
371+
# new_atoms = set(type_map) - set(self.data["atom_names"])
372+
new_atoms = [e for e in type_map if e not in self.data["atom_names"]]
372373
if new_atoms:
373374
self.add_atom_names(new_atoms)
374375
# index that will sort an array by type_map
@@ -414,8 +415,8 @@ def formula(self):
414415
"""
415416
Return the formula of this system, like C3H5O2
416417
"""
417-
return ''.join(["{}{}".format(symbol,numb) for symbol,numb in sorted(
418-
zip(self.data['atom_names'], self.data['atom_numbs']))])
418+
return ''.join(["{}{}".format(symbol,numb) for symbol,numb in
419+
zip(self.data['atom_names'], self.data['atom_numbs'])])
419420

420421

421422
def extend(self, systems):
@@ -1455,29 +1456,31 @@ def check_atom_names(self, system):
14551456
"""
14561457
Make atom_names in all systems equal, prevent inconsistent atom_types.
14571458
"""
1458-
new_in_system = set(system["atom_names"]) - set(self.atom_names)
1459-
new_in_self = set(self.atom_names) - set(system["atom_names"])
1459+
# new_in_system = set(system["atom_names"]) - set(self.atom_names)
1460+
# new_in_self = set(self.atom_names) - set(system["atom_names"])
1461+
new_in_system = [e for e in system["atom_names"] if e not in self.atom_names]
1462+
new_in_self = [e for e in self.atom_names if e not in system["atom_names"]]
14601463
if len(new_in_system):
14611464
# A new atom_name appear, add to self.atom_names
14621465
self.atom_names.extend(new_in_system)
1463-
self.atom_names.sort()
14641466
# Add this atom_name to each system, and change their names
14651467
new_systems = {}
14661468
for each_system in self.systems.values():
14671469
each_system.add_atom_names(new_in_system)
1468-
each_system.sort_atom_names()
1470+
each_system.sort_atom_names(type_map=self.atom_names)
14691471
new_systems[each_system.formula] = each_system
14701472
self.systems = new_systems
14711473
if len(new_in_self):
14721474
# Previous atom_name not in this system
14731475
system.add_atom_names(new_in_self)
1474-
system.sort_atom_names()
1476+
system.sort_atom_names(type_map=self.atom_names)
14751477

14761478
def from_quip_gap_xyz_file(self,file_name):
14771479
# quip_gap_xyz_systems = QuipGapxyzSystems(file_name)
14781480
# print(next(quip_gap_xyz_systems))
14791481
for info_dict in QuipGapxyzSystems(file_name):
14801482
system=LabeledSystem(data=info_dict)
1483+
system.sort_atom_names()
14811484
self.append(system)
14821485

14831486

0 commit comments

Comments
 (0)