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 heating fixes #133 #134

Merged
merged 8 commits into from
May 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 26 additions & 7 deletions janus_core/calculations/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Run molecular dynamics simulations."""

import datetime
from math import isclose
from pathlib import Path
import random
from typing import Any, Optional
Expand Down Expand Up @@ -292,10 +293,16 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals,too-many-sta

# Warn if mix of None and not None
self.ramp_temp = (
self.temp_start and self.temp_end and self.temp_step and self.temp_time
self.temp_start is not None
ElliottKasoar marked this conversation as resolved.
Show resolved Hide resolved
and self.temp_end is not None
and self.temp_step
and self.temp_time
)
if (
self.temp_start or self.temp_end or self.temp_step or self.temp_time
self.temp_start is not None
or self.temp_end is not None
or self.temp_step
or self.temp_time
) and not self.ramp_temp:
warn(
"`temp_start`, `temp_end` and `temp_step` must all be specified for "
alinelena marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -335,12 +342,16 @@ def _set_velocity_distribution(self) -> None:
Sets Maxwell-Boltzmann velocity distribution, as well as removing
centre-of-mass momentum, and (optionally) total angular momentum.
"""
MaxwellBoltzmannDistribution(self.struct, temperature_K=self.temp)
Stationary(self.struct)
atoms = self.struct
alinelena marked this conversation as resolved.
Show resolved Hide resolved
if self.dyn.nsteps >= 0:
atoms = self.dyn.atoms
ElliottKasoar marked this conversation as resolved.
Show resolved Hide resolved

MaxwellBoltzmannDistribution(atoms, temperature_K=self.temp)
Stationary(atoms)
if self.logger:
self.logger.info("Velocities reset at step %s", self.dyn.nsteps)
if self.remove_rot:
ZeroRotation(self.struct)
ZeroRotation(atoms)
if self.logger:
self.logger.info("Rotation reset at step %s", self.dyn.nsteps)

Expand Down Expand Up @@ -373,7 +384,7 @@ def _parameter_prefix(self) -> str:
"""

temperature_prefix = ""
if self.temp_start and self.temp_end:
if self.temp_start is not None and self.temp_end:
alinelena marked this conversation as resolved.
Show resolved Hide resolved
temperature_prefix = f"-T{self.temp_start}-T{self.temp_end}"

if self.steps > 0:
Expand Down Expand Up @@ -607,7 +618,12 @@ def _run_dynamics(self) -> None:
if self.logger:
self.logger.info("Beginning temperature ramp at %sK", temps[0])
for temp in temps:
if isclose(temp, 0.0):
continue
alinelena marked this conversation as resolved.
Show resolved Hide resolved
self.temp = temp
self._set_velocity_distribution()
if not isinstance(self, NVE):
self.dyn.set_temperature(temperature_K=self.temp)
self.dyn.run(heating_steps)
self._write_final_state()
if self.logger:
Expand All @@ -618,6 +634,10 @@ def _run_dynamics(self) -> None:
if self.logger:
self.logger.info("Starting molecular dynamics simulation")
self.temp = md_temp
if self.ramp_temp:
self._set_velocity_distribution()
if not isinstance(self, NVE):
self.dyn.set_temperature(temperature_K=self.temp)
self.dyn.run(self.steps)
self._write_final_state()
if self.logger:
Expand Down Expand Up @@ -697,7 +717,6 @@ def __init__(
pfactor = (barostat_time * units.fs) ** 2 * scaled_bulk_modulus
else:
pfactor = None

self.dyn = ASE_NPT(
self.struct,
timestep=self.timestep,
Expand Down