Skip to content

Commit

Permalink
Added function to set MD starting temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
bowen-bd committed Oct 26, 2023
1 parent 4699074 commit 7c8139d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions chgnet/model/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ase.md.npt import NPT
from ase.md.nptberendsen import Inhomogeneous_NPTBerendsen, NPTBerendsen
from ase.md.nvtberendsen import NVTBerendsen
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution, Stationary
from ase.md.verlet import VelocityVerlet
from ase.optimize.bfgs import BFGS
from ase.optimize.bfgslinesearch import BFGSLineSearch
Expand Down Expand Up @@ -355,6 +356,7 @@ def __init__(
ensemble: str = "nvt",
thermostat: str = "Berendsen_inhomogeneous",
temperature: int = 300,
starting_temperature: int | None = None,
timestep: float = 2.0,
pressure: float = 1.01325e-4,
taut: float | None = None,
Expand Down Expand Up @@ -382,6 +384,10 @@ def __init__(
Default = "Nose-Hoover"
temperature (float): temperature for MD simulation, in K
Default = 300
starting_temperature (float): starting temperature of MD simulation, in K
if set as None, the MD starts with the momentum carried by ase.Atoms
if input is a pymatgen.core.Structure, the MD starts at 0K
Default = None
timestep (float): time step in fs
Default = 2
pressure (float): pressure in GPa
Expand Down Expand Up @@ -434,6 +440,12 @@ def __init__(
if isinstance(atoms, (Structure, Molecule)):
atoms = atoms.to_ase_atoms()

if starting_temperature is not None:
MaxwellBoltzmannDistribution(
atoms, temperature_K=starting_temperature, force_temp=True
)
Stationary(atoms)

self.atoms = atoms
if isinstance(model, CHGNetCalculator):
self.atoms.calc = model
Expand Down
14 changes: 9 additions & 5 deletions chgnet/utils/vasp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def solve_charge_by_mag(
(4.2, 5): 2
))
"""
out_structure = structure.copy()
out_structure.remove_oxidation_states()
ox_list = []
solved_ox = True
default_ox = default_ox or {"Li": 1, "O": -2}
Expand All @@ -183,10 +185,10 @@ def solve_charge_by_mag(
}

mag = structure.site_properties.get(
"final_magmom", structure.site_properties.get("magmom")
"magmom", structure.site_properties.get("magmom")
)

for idx, site in enumerate(structure):
for idx, site in enumerate(out_structure):
assigned = False
if site.species_string in ox_ranges:
for (min_mag, max_mag), mag_ox in ox_ranges[site.species_string].items():
Expand All @@ -201,7 +203,9 @@ def solve_charge_by_mag(
solved_ox = False

if solved_ox:
print(ox_list)
structure.add_oxidation_state_by_site(ox_list)
return structure
total_charge = sum(ox_list)
print(f"Solvec oxidation state, total charge={total_charge}")
out_structure.add_oxidation_state_by_site(ox_list)
return out_structure
print("Failed to solve oxidation state")
return None

0 comments on commit 7c8139d

Please sign in to comment.