Skip to content

Commit

Permalink
Add heating CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Apr 10, 2024
1 parent a3e4cdb commit 486df71
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
28 changes: 28 additions & 0 deletions janus_core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,20 @@ def md(
traj_every: Annotated[
int, typer.Option(help="Frequency of steps to save trajectory.")
] = 100,
temp_start: Annotated[
Optional[float],
typer.Option(help="Temperature to start heating, in K. [default: None]"),
] = None,
temp_end: Annotated[
Optional[float],
typer.Option(help="Maximum temperature for heating, in K. [default: None]"),
] = None,
temp_step: Annotated[
float, typer.Option(help="Size of temperature steps when heating, in K.")
] = 10,
temp_time: Annotated[
float, typer.Option(help="Time between heating steps, in fs.")
] = 10,
log: LogPath = "md.log",
seed: Annotated[
Optional[int],
Expand Down Expand Up @@ -749,6 +763,16 @@ def md(
Step to start saving trajectory. Default is 0.
traj_every : int
Frequency of steps to save trajectory. Default is 100.
temp_start : Optional[float]
Temperature to start heating, in K. Default is None, which disables
heating.
temp_end : Optional[float]
Maximum temperature for heating, in K. Default is None, which disables
heating.
temp_step : float
Size of temperature steps when heating, in K. Default is 10.
temp_time : float
Time between heating steps, in fs. Default is 10.
log : Optional[Path]
Path to write logs to. Default is "md.log".
seed : Optional[int]
Expand Down Expand Up @@ -808,6 +832,10 @@ def md(
"traj_append": traj_append,
"traj_start": traj_start,
"traj_every": traj_every,
"temp_start": temp_start,
"temp_end": temp_end,
"temp_step": temp_step,
"temp_time": temp_time,
"log_kwargs": log_kwargs,
"seed": seed,
}
Expand Down
8 changes: 4 additions & 4 deletions janus_core/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MolecularDynamics: # pylint: disable=too-many-instance-attributes
temp_start : Optional[float]
Temperature to start heating, in K. Default is None, which disables heating.
temp_end : Optional[float]
Temperature to finish heating, in K. Default is None, which disables heating.
Maximum temperature for heating, in K. Default is None, which disables heating.
temp_step : float
Size of temperature steps when heating, in K. Default is 10.
temp_time : float
Expand Down Expand Up @@ -232,7 +232,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals,too-many-sta
Temperature to start heating, in K. Default is None, which disables
heating.
temp_end : Optional[float]
Temperature to finish heating, in K. Default is None, which disables
Maximum temperature for heating, in K. Default is None, which disables
heating.
temp_step : float
Size of temperature steps when heating, in K. Default is 10.
Expand Down Expand Up @@ -529,9 +529,9 @@ def _run_dynamics(self) -> None:

# Run temperature ramp
if self.temp_start and self.temp_end and self.temp_step:
heating_steps = self.temp_time // self.timestep
heating_steps = int(self.temp_time // self.timestep)

n_temps = 1 + (self.temp_end - self.temp_start) // self.temp_step
n_temps = int(1 + (self.temp_end - self.temp_start) // self.temp_step)
temps = [self.temp_start + i * self.temp_step for i in range(n_temps)]

if self.logger:
Expand Down
37 changes: 37 additions & 0 deletions tests/test_md_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,40 @@ def test_config(tmp_path):
assert md_summary["inputs"]["temp"] == 200
# Check explicit option overwrites config
assert md_summary["inputs"]["ensemble"] == "nve"


def test_heating(tmp_path):
"""Test heating before MD."""
file_prefix = tmp_path / "nvt-T300"
log_path = tmp_path / "test.log"
summary_path = tmp_path / "summary.yml"

result = runner.invoke(
app,
[
"md",
"--ensemble",
"nvt",
"--struct",
DATA_PATH / "NaCl.cif",
"--file-prefix",
file_prefix,
"--stats-every",
1,
"--steps",
5,
"--temp-start",
10,
"--temp-end",
20,
"--temp-step",
50,
"--temp-time",
0.05,
"--log",
log_path,
"--summary",
summary_path,
],
)
assert result.exit_code == 0

0 comments on commit 486df71

Please sign in to comment.