Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #339 #342

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions python/BioSimSpace/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2131,16 +2131,31 @@ def _add_position_restraints(self):
)

with open(restraint_file, "w") as file:
# Write the header.
file.write("[ position_restraints ]\n")
file.write("; i funct fcx fcy fcz\n")

# Write restraints for each atom.
for atom_idx in restrained_atoms:
if isinstance(self._protocol, _FreeEnergyMixin):
# Write the header.
file.write("[ position_restraints ]\n")
file.write(
f"{atom_idx+1:4} 1 {force_constant} {force_constant} {force_constant}\n"
"; i funct fcx_A fcy_A fcz_A fcx_B fcy_B fcz_B\n"
)
# Write restraints for each atom.
for atom_idx in restrained_atoms:
file.write(
f"{atom_idx+1:4} 1 {force_constant} {force_constant} {force_constant} {force_constant} {force_constant} {force_constant}\n"
)

else:
# Write the header.
file.write("[ position_restraints ]\n")
file.write(
"; i funct fcx fcy fcz\n"
)

# Write restraints for each atom.
for atom_idx in restrained_atoms:
file.write(
f"{atom_idx+1:4} 1 {force_constant} {force_constant} {force_constant}\n"
)

# Work out the offset.
offset = num_restraint - 1

Expand Down
11 changes: 11 additions & 0 deletions tests/Process/test_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def test_restraints(perturbable_system, restraint):
process = BSS.Process.Gromacs(perturbable_system, protocol)


@pytest.mark.skipif(has_gromacs is False, reason="Requires GROMACS to be installed.")
def test_perturbable_restraint(perturbable_system):
"""Test a free energy perturbation protocol."""

# Create a short minimisation protocol with a restraint.
protocol = BSS.Protocol.Minimisation(steps=100, restraint="heavy")

# Run the process, check that it finished without error, and returns a system.
run_process(perturbable_system, protocol)


def run_process(system, protocol, **kwargs):
"""Helper function to run various simulation protocols."""

Expand Down
Loading