Skip to content

Commit 0afe158

Browse files
committed
Log REST2 scale factors and selection atoms.
1 parent 8247c99 commit 0afe158

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

src/somd2/runner/_base.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def __init__(self, system, config):
363363
from math import isclose
364364

365365
# Set the REST2 scale factors.
366+
is_rest2 = False
366367
if self._config.rest2_scale is not None:
367368
# Single value. Interpolate between 1.0 at the end states and rest2_scale
368369
# at lambda = 0.5.
@@ -396,6 +397,39 @@ def __init__(self, system, config):
396397
raise ValueError(msg)
397398
self._rest2_scale_factors = self._config.rest2_scale
398399

400+
# If there are any non-zero REST2 scale factors, then log it.
401+
if any(
402+
not isclose(factor, 1.0, abs_tol=1e-4)
403+
for factor in self._rest2_scale_factors
404+
):
405+
is_rest2 = True
406+
_logger.info(f"REST2 scaling factors: {self._rest2_scale_factors}")
407+
408+
# Make sure the REST2 selection is valid.
409+
if self._config.rest2_selection is not None:
410+
411+
try:
412+
atoms = _sr.mol.selection_to_atoms(
413+
self._system, self._config.rest2_selection
414+
)
415+
except:
416+
msg = "Invalid 'rest2_selection' value."
417+
_logger.error(msg)
418+
raise ValueError(msg)
419+
420+
# Make sure the user hasn't selected all atoms.
421+
if len(atoms) == self._system.num_atoms():
422+
msg = "REST2 selection cannot contain all atoms in the system."
423+
_logger.error(msg)
424+
raise ValueError(msg)
425+
else:
426+
atoms = _sr.mol.selection_to_atoms(self._system, "property is_perturbable")
427+
428+
# Log the atom indices in the REST2 selection.
429+
if is_rest2:
430+
idxs = self._system.atoms().find(atoms)
431+
_logger.info(f"REST2 selection contains {len(atoms)} atoms: {idxs}")
432+
399433
# Apply hydrogen mass repartitioning.
400434
if self._config.hmr:
401435
# Work out the current hydrogen mass factor.
@@ -444,23 +478,6 @@ def __init__(self, system, config):
444478
self._system, self._config.h_mass_factor
445479
)
446480

447-
# Make sure the REST2 selection is valid.
448-
if self._config.rest2_selection is not None:
449-
from sire.mol import selection_to_atoms
450-
451-
try:
452-
atoms = selection_to_atoms(self._system, self._config.rest2_selection)
453-
except:
454-
msg = "Invalid 'rest2_selection' value."
455-
_logger.error(msg)
456-
raise ValueError(msg)
457-
458-
# Make sure the user hasn't selected all atoms.
459-
if len(atoms) == self._system.num_atoms():
460-
msg = "REST2 selection cannot contain all atoms in the system."
461-
_logger.error(msg)
462-
raise ValueError(msg)
463-
464481
# Flag whether this is a GPU simulation.
465482
self._is_gpu = self._config.platform in ["cuda", "opencl", "hip"]
466483

0 commit comments

Comments
 (0)