Skip to content

Commit 0130f1b

Browse files
committed
ASEInterface: removed unnecessary type-mapping
1 parent 9b5c24a commit 0130f1b

File tree

7 files changed

+6
-62
lines changed

7 files changed

+6
-62
lines changed

src/python/espressomd/plugins/ase.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,24 @@ class ASEInterface:
3232
ASE interface for ESPResSo.
3333
"""
3434

35-
type_mapping: dict
36-
"""
37-
Mapping of ESPResSo particle types to ASE symbols. E.g. ``{0: "H", 1: "O"}``.
38-
"""
3935
_system: typing.Union["System", None] = None
4036

4137
def register_system(self, system):
4238
"""Register the system."""
4339
self._system = system
4440

45-
def __getstate__(self):
46-
return {"type_mapping": self.type_mapping}
47-
4841
def get(self, folded=False) -> ase.Atoms:
4942
"""Export the ESPResSo system particle data to an ASE atoms object."""
5043
particles = self._system.part.all()
5144
positions = np.copy(particles.pos_folded if folded else particles.pos)
5245
types = np.copy(particles.type)
5346
forces = np.copy(particles.f)
54-
unknown_types = set(types) - set(self.type_mapping)
55-
if unknown_types:
56-
raise RuntimeError(
57-
f"Particle types '{unknown_types}' haven't been registered in the ASE type map" # nopep8
58-
)
5947
if any(p.is_virtual() for p in particles):
6048
raise RuntimeError("ASE doesn't support virtual sites")
6149

6250
atoms = ase.Atoms(
6351
positions=positions,
64-
symbols=[self.type_mapping[t] for t in types],
52+
numbers=types,
6553
pbc=np.copy(self._system.periodicity),
6654
cell=np.copy(self._system.box_l),
6755
)

src/python/espressomd/system.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,10 @@ def __getstate__(self):
175175
odict = collections.OrderedDict()
176176
for property_name in checkpointable_properties:
177177
odict[property_name] = System.__getattribute__(self, property_name)
178-
if self._ase_interface is not None:
179-
odict["_ase_interface"] = self._ase_interface.__getstate__()
180178
return odict
181179

182180
def __setstate__(self, params):
183181
# initialize Python-only members
184-
if "_ase_interface" in params:
185-
from espressomd.plugins.ase import ASEInterface
186-
self.ase = ASEInterface(**params.pop("_ase_interface"))
187182
for property_name in params.keys():
188183
System.__setattr__(self, property_name, params[property_name])
189184
# note: several members can only be instantiated once

src/python/espressomd/zn.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ def update(self):
320320
particles = self.system.part.all()
321321
all_types = particles.type
322322
self.system.visualizer_params = self.params
323-
Asedata = ase.ASEInterface(
324-
{x: "X" for x in set(all_types)})
323+
Asedata = ase.ASEInterface()
325324
Asedata.register_system(self.system)
326325
data = Asedata.get(folded=self.params["folded"])
327326
if self.params["colors"] is not None:

testsuite/python/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ checkpoint_test(MODES dp3m_cpu__therm_langevin__int_nvt)
217217
checkpoint_test(MODES therm_dpd__int_nvt)
218218
checkpoint_test(MODES scafacos__therm_bd__int_bd)
219219
checkpoint_test(MODES therm_sdm__int_sdm)
220-
checkpoint_test(MODES lj__ase SUFFIX 1_core MAX_NUM_PROC 1)
221220

222221
python_test(FILE bond_breakage.py MAX_NUM_PROC 4)
223222
python_test(FILE cell_system.py MAX_NUM_PROC 4)

testsuite/python/ase_interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def setUp(self):
3434
self.system.part.add(pos=[0., 0., 0.], f=[1., -1., 0.], type=0)
3535
self.system.part.add(pos=[0., 0., 1.], f=[0., 12., 0.], type=1)
3636
self.system.part.add(pos=[11., 13., 12.], f=[0., 0., -8.], type=1)
37-
self.system.ase = espressomd.plugins.ase.ASEInterface(
38-
type_mapping={0: "H", 1: "O"},
39-
)
37+
self.system.ase = espressomd.plugins.ase.ASEInterface()
4038

4139
def tearDown(self):
4240
self.system.part.clear()

testsuite/python/save_checkpoint.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import unittest as ut
2121
import unittest_generator as utg
2222
import numpy as np
23-
import contextlib
2423
import pathlib
2524
import tempfile
26-
import sys
2725

2826
import espressomd
2927
import espressomd.checkpointing
@@ -43,8 +41,6 @@
4341
import espressomd.bond_breakage
4442
import espressomd.reaction_methods
4543

46-
with contextlib.suppress(ImportError):
47-
import espressomd.plugins.ase
4844

4945
config = utg.TestGenerator()
5046
modes = config.get_modes()
@@ -74,8 +70,6 @@
7470
system.lees_edwards.set_boundary_conditions(
7571
shear_direction="z", shear_plane_normal="y", protocol=protocol)
7672

77-
has_ase = "ASE" in modes
78-
7973
lbf_class = None
8074
lb_lattice = None
8175
if espressomd.has_features('WALBERLA') and 'LB.WALBERLA' in modes:
@@ -170,11 +164,6 @@
170164
system.electrostatics.solver = p3m
171165
p3m.charge_neutrality_tolerance = 5e-12
172166

173-
if has_ase and "ase" in sys.modules:
174-
system.ase = espressomd.plugins.ase.ASEInterface(
175-
type_mapping={0: "H", 1: "O", 10: "Cl"},
176-
)
177-
178167
# accumulators
179168
obs = espressomd.observables.ParticlePositions(ids=[0, 1])
180169
obs_dist = espressomd.observables.PairwiseDistances(
@@ -259,7 +248,7 @@
259248
approximation_method='ft', viscosity=0.5, radii={0: 1.5},
260249
pair_mobility=False, self_mobility=True)
261250

262-
if espressomd.has_features(['VIRTUAL_SITES_RELATIVE']) and not has_ase:
251+
if espressomd.has_features(['VIRTUAL_SITES_RELATIVE']):
263252
p2.vs_auto_relate_to(p1, couple_to_lb=lbf_class is not None)
264253

265254
# non-bonded interactions
@@ -477,7 +466,6 @@
477466
if espressomd.has_features(["ENGINE"]):
478467
p3.swimming = {"f_swim": 0.03}
479468
if espressomd.has_features(["ENGINE", "VIRTUAL_SITES_RELATIVE"]) and lbf_class:
480-
assert not has_ase
481469
p4.swimming = {"v_swim": 0.02, "is_engine_force_on_fluid": True}
482470
if espressomd.has_features('LB_ELECTROHYDRODYNAMICS') and lbf_class:
483471
p8.mu_E = [-0.1, 0.2, -0.3]

testsuite/python/test_checkpoint.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
with contextlib.suppress(ImportError):
4242
import espressomd.io.vtk
4343

44-
with contextlib.suppress(ImportError):
45-
import ase
46-
import espressomd.plugins.ase
47-
4844
with contextlib.suppress(ImportError):
4945
import h5py # h5py has to be imported *after* espressomd (MPI)
5046

@@ -57,7 +53,6 @@
5753
has_thermalized_bonds = 'THERM.LB' in modes or 'THERM.LANGEVIN' in modes
5854
has_drude = (espressomd.has_features(['ELECTROSTATICS', 'MASS', 'ROTATION'])
5955
and has_thermalized_bonds)
60-
has_ase = 'ASE' in modes
6156

6257

6358
class CheckpointTest(ut.TestCase):
@@ -472,14 +467,13 @@ def test_particle_properties(self):
472467
self.assertEqual(
473468
p3.swimming,
474469
{"f_swim": 0.03, "is_engine_force_on_fluid": False})
475-
if espressomd.has_features(
476-
'VIRTUAL_SITES_RELATIVE') and has_lb_mode and not has_ase:
470+
if espressomd.has_features('VIRTUAL_SITES_RELATIVE') and has_lb_mode:
477471
self.assertEqual(
478472
p4.swimming,
479473
{"f_swim": 0., "is_engine_force_on_fluid": True})
480474
if espressomd.has_features('LB_ELECTROHYDRODYNAMICS') and has_lb_mode:
481475
np.testing.assert_allclose(np.copy(p8.mu_E), [-0.1, 0.2, -0.3])
482-
if espressomd.has_features('VIRTUAL_SITES_RELATIVE') and not has_ase:
476+
if espressomd.has_features('VIRTUAL_SITES_RELATIVE'):
483477
from scipy.spatial.transform import Rotation as R
484478
q_ind = ([1, 2, 3, 0],) # convert from scalar-first to scalar-last
485479
vs_id, vs_dist, vs_quat = p2.vs_relative
@@ -765,7 +759,6 @@ def test_drude_helpers(self):
765759
self.assertEqual(dh.drude_id_list, [5])
766760

767761
@utx.skipIfMissingFeatures(['VIRTUAL_SITES', 'VIRTUAL_SITES_RELATIVE'])
768-
@ut.skipIf("ASE" in modes, "virtual sites not allowed by ASE")
769762
def test_virtual_sites(self):
770763
Propagation = espressomd.propagation.Propagation
771764
p_real = system.part.by_id(0)
@@ -1068,22 +1061,6 @@ def test_union(self):
10681061
p2.remove()
10691062
system.non_bonded_inter[2, 6].reset()
10701063

1071-
@ut.skipIf("ase" not in sys.modules, "missing module 'ase'")
1072-
@ut.skipIf("ASE" not in modes, "missing combination")
1073-
def test_ase_plugin(self):
1074-
atoms = system.ase.get()
1075-
self.assertIsNotNone(atoms)
1076-
self.assertIsInstance(atoms, ase.Atoms)
1077-
self.assertEqual(set(atoms.get_chemical_symbols()), {"H", "O"})
1078-
np.testing.assert_equal(atoms.pbc, np.copy(system.periodicity))
1079-
np.testing.assert_allclose(atoms.cell, np.diag(system.box_l))
1080-
np.testing.assert_allclose(
1081-
atoms.get_positions(),
1082-
np.copy(system.part.select(lambda p: p.type in [0, 1]).pos))
1083-
np.testing.assert_allclose(
1084-
atoms.get_forces(),
1085-
np.copy(system.part.select(lambda p: p.type in [0, 1]).f))
1086-
10871064

10881065
if __name__ == '__main__':
10891066
config.bind_test_class(CheckpointTest)

0 commit comments

Comments
 (0)