Skip to content

Commit

Permalink
Fixed reading of coord file with "natoms= ..." in first line.
Browse files Browse the repository at this point in the history
Fixed test that now fails when running define with frozen cartesian
coordinates + frozen internal coordinates.
  • Loading branch information
davidwaroquiers committed Feb 22, 2024
1 parent bd3ae44 commit b24639b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion turbomoleio/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_mol_and_indices_frozen(
# with the final f meaning that the coordinate is frozen.
for line in lines:
s = line.split()
if not s or s[0].startswith("#"):
if not s or s[0].startswith("#") or s[0].strip().startswith("natoms="):
continue
iatom += 1
coords.append([float(i) * bohr_to_ang for i in s[0:3]])
Expand Down
26 changes: 24 additions & 2 deletions turbomoleio/integration_tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
OutOfPlaneAngle,
PerpendicularBendingAngle,
)
from turbomoleio.input.define import DefineRunner
from turbomoleio.input.define import DefineIredError, DefineRunner
from turbomoleio.testfiles.utils import assert_MSONable, temp_dir

dr_parameters = dict(ired=True)
Expand All @@ -49,7 +49,16 @@
@pytest.mark.parametrize("molecule_filename", ["ch4.json"])
class TestMoleculeSystem:
def test_distance(self, molecule, control_filepath, delete_tmp_dir):
ms = MoleculeSystem(molecule, frozen_indices={2, 3})
# Having frozen cartesian coordinates AND internal coordinates frozen
# is (currently) not supported by Turbomole. Before version 7.7,
# the define executable would still allow to update the internal
# coordinates, but then the Turbomole executable (e.g. dscf, ridft, ...)
# would anyway fail. For Turbomole >= 7.7, define directly forbids to
# freeze cartesian and internal coordinates.
# A new integration test checks that.
# ms = MoleculeSystem(molecule, frozen_indices={2, 3})
ms = MoleculeSystem(molecule)

ms.add_distance(0, 1, weights=1.0, value=2.5)
assert ms.has_inconsistencies()

Expand Down Expand Up @@ -83,6 +92,19 @@ def test_distance(self, molecule, control_filepath, delete_tmp_dir):

assert_MSONable(ms_new)

def test_distance_frozen_cart_int(self, molecule, control_filepath, delete_tmp_dir):
ms = MoleculeSystem(molecule, frozen_indices={2, 3})

ms.add_distance(0, 1, weights=1.0, value=2.5)
assert ms.has_inconsistencies()
with temp_dir(delete_tmp_dir):
ms.to_file("coord", fmt="coord")
shutil.copy2(control_filepath, "control")
dr = DefineRunner(parameters=dr_parameters)
# This raises for Turbomole version >= 7.7.
with pytest.raises(DefineIredError):
dr.run_update_internal_coords()

def test_distance_no_val(self, molecule, control_filepath, delete_tmp_dir):
ms = MoleculeSystem(molecule)
ms.add_distance(0, 1, weights=1.0, value=None)
Expand Down

0 comments on commit b24639b

Please sign in to comment.