Fixes Continue from Last Run and Implements Geoms File
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,3 +14,5 @@ simfiles/*
|
|||||||
.vscode/*
|
.vscode/*
|
||||||
.idea/*
|
.idea/*
|
||||||
*.pkl
|
*.pkl
|
||||||
|
|
||||||
|
*.xyz
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ diceplayer:
|
|||||||
|
|
||||||
dice:
|
dice:
|
||||||
nmol: [1, 100]
|
nmol: [1, 100]
|
||||||
dens: 1.0
|
dens: 1.5
|
||||||
nstep: [2000, 3000]
|
nstep: [2000, 3000]
|
||||||
isave: 1000
|
isave: 1000
|
||||||
outname: 'phb'
|
outname: 'phb'
|
||||||
progname: '~/.local/bin/dice'
|
progname: '~/.local/bin/dice'
|
||||||
ljname: 'phb.ljc'
|
ljname: 'phb.ljc'
|
||||||
randominit: 'first'
|
randominit: 'always'
|
||||||
|
|
||||||
gaussian:
|
gaussian:
|
||||||
qmprog: 'g16'
|
qmprog: 'g16'
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ def main():
|
|||||||
player.read_potentials()
|
player.read_potentials()
|
||||||
|
|
||||||
player.create_simulation_dir()
|
player.create_simulation_dir()
|
||||||
|
player.create_geoms_file()
|
||||||
|
|
||||||
player.print_keywords()
|
player.print_keywords()
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from diceplayer.shared.utils.misc import weekday_date_time
|
|||||||
from diceplayer.shared.environment.molecule import Molecule
|
from diceplayer.shared.environment.molecule import Molecule
|
||||||
from diceplayer.shared.environment.system import System
|
from diceplayer.shared.environment.system import System
|
||||||
from diceplayer.shared.environment.atom import Atom
|
from diceplayer.shared.environment.atom import Atom
|
||||||
|
from diceplayer.shared.utils.ptable import atomsymb
|
||||||
from diceplayer import logger
|
from diceplayer import logger
|
||||||
|
|
||||||
from dataclasses import fields
|
from dataclasses import fields
|
||||||
@@ -19,6 +20,7 @@ import yaml
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
ENV = ["OMP_STACKSIZE"]
|
ENV = ["OMP_STACKSIZE"]
|
||||||
|
|
||||||
|
|
||||||
@@ -28,10 +30,8 @@ class Player:
|
|||||||
raise ValueError("Must specify either infile or optimization")
|
raise ValueError("Must specify either infile or optimization")
|
||||||
|
|
||||||
elif infile is not None:
|
elif infile is not None:
|
||||||
config_data = self.read_keywords(infile)
|
|
||||||
|
|
||||||
self.config = self.set_config(
|
self.config = self.set_config(
|
||||||
config_data.get("diceplayer")
|
self.read_keywords(infile)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.system = System()
|
self.system = System()
|
||||||
@@ -45,7 +45,7 @@ class Player:
|
|||||||
|
|
||||||
self.system = save[1]
|
self.system = save[1]
|
||||||
|
|
||||||
self.initial_cycle = save[2]
|
self.initial_cycle = save[2] + 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Must specify either infile or config")
|
raise ValueError("Must specify either infile or config")
|
||||||
@@ -60,7 +60,7 @@ class Player:
|
|||||||
"==========================================================================================\n"
|
"==========================================================================================\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
for cycle in range(self.initial_cycle, self.config.maxcyc + 1):
|
for cycle in range(self.initial_cycle, self.initial_cycle + self.config.maxcyc + 1):
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"------------------------------------------------------------------------------------------\n"
|
f"------------------------------------------------------------------------------------------\n"
|
||||||
@@ -72,8 +72,7 @@ class Player:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.gaussian_start(cycle)
|
self.gaussian_start(cycle)
|
||||||
pass
|
except StopIteration:
|
||||||
except StopIteration as e:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
self.save_run_in_pickle(cycle)
|
self.save_run_in_pickle(cycle)
|
||||||
@@ -105,6 +104,15 @@ class Player:
|
|||||||
)
|
)
|
||||||
simulation_dir_path.mkdir()
|
simulation_dir_path.mkdir()
|
||||||
|
|
||||||
|
def create_geoms_file(self):
|
||||||
|
geoms_file_path = Path(self.config.geoms_file)
|
||||||
|
if geoms_file_path.exists():
|
||||||
|
raise FileExistsError(
|
||||||
|
f"Error: a file or a directory {self.config.geoms_file} already exists,"
|
||||||
|
f" move or delete the simfiles directory to continue."
|
||||||
|
)
|
||||||
|
geoms_file_path.touch()
|
||||||
|
|
||||||
def print_keywords(self) -> None:
|
def print_keywords(self) -> None:
|
||||||
|
|
||||||
def log_keywords(config: Dataclass, dto: Type[Dataclass]):
|
def log_keywords(config: Dataclass, dto: Type[Dataclass]):
|
||||||
@@ -295,6 +303,7 @@ class Player:
|
|||||||
.update_charges(result['charges'])
|
.update_charges(result['charges'])
|
||||||
|
|
||||||
self.system.print_charges_and_dipole(cycle)
|
self.system.print_charges_and_dipole(cycle)
|
||||||
|
self.print_geoms(cycle)
|
||||||
|
|
||||||
if diff < self.config.gaussian.chg_tol:
|
if diff < self.config.gaussian.chg_tol:
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -302,6 +311,18 @@ class Player:
|
|||||||
)
|
)
|
||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
|
|
||||||
|
def print_geoms(self, cycle: int):
|
||||||
|
with open(self.config.geoms_file, 'a') as file:
|
||||||
|
file.write(f'Cycle # {cycle}\n')
|
||||||
|
|
||||||
|
for atom in self.system.molecule[0].atom:
|
||||||
|
symbol = atomsymb[atom.na]
|
||||||
|
file.write(
|
||||||
|
f'{symbol:<2s} {atom.rx:>10.6f} {atom.ry:>10.6f} {atom.rz:>10.6f}\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
file.write('\n')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_atom_dict(molecule_type, molecule_site, atom_dict: dict) -> dict:
|
def validate_atom_dict(molecule_type, molecule_site, atom_dict: dict) -> dict:
|
||||||
molecule_type += 1
|
molecule_type += 1
|
||||||
@@ -442,7 +463,14 @@ class Player:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def read_keywords(infile) -> dict:
|
def read_keywords(infile) -> dict:
|
||||||
with open(infile, 'r') as yml_file:
|
with open(infile, 'r') as yml_file:
|
||||||
return yaml.load(yml_file, Loader=yaml.SafeLoader)
|
config = yaml.load(yml_file, Loader=yaml.SafeLoader)
|
||||||
|
|
||||||
|
if "diceplayer" in config:
|
||||||
|
return config.get("diceplayer")
|
||||||
|
|
||||||
|
raise RuntimeError(
|
||||||
|
f'Could not find diceplayer section in {infile}.'
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls, infile: str) -> 'Player':
|
def from_file(cls, infile: str) -> 'Player':
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class PlayerConfig(Dataclass):
|
|||||||
switchcyc: int = 3
|
switchcyc: int = 3
|
||||||
qmprog: str = 'g16'
|
qmprog: str = 'g16'
|
||||||
altsteps: int = 20000
|
altsteps: int = 20000
|
||||||
|
geoms_file = 'geoms.xyz'
|
||||||
simulation_dir = 'simfiles'
|
simulation_dir = 'simfiles'
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
|
|||||||
@@ -166,11 +166,14 @@ class DiceInterface(Interface):
|
|||||||
def _make_init_file(self, proc_dir: Path, last_xyz_file: TextIO):
|
def _make_init_file(self, proc_dir: Path, last_xyz_file: TextIO):
|
||||||
xyz_lines = last_xyz_file.readlines()
|
xyz_lines = last_xyz_file.readlines()
|
||||||
|
|
||||||
nsites_mm = 0
|
HEADER_LENGTH = 2
|
||||||
for i in range(1, len(self.step.dice.nmol)):
|
MAIN_MOLECULE_LENGTH = len(self.system.molecule[0].atom)
|
||||||
nsites_mm += self.step.dice.nmol[i] * len(self.system.molecule[i].atom)
|
|
||||||
|
|
||||||
xyz_lines = xyz_lines[-nsites_mm:]
|
SECONDARY_MOLECULES_LENGTH = HEADER_LENGTH + MAIN_MOLECULE_LENGTH
|
||||||
|
for i in range(1, len(self.step.dice.nmol)):
|
||||||
|
SECONDARY_MOLECULES_LENGTH += self.step.dice.nmol[i] * len(self.system.molecule[i].atom)
|
||||||
|
|
||||||
|
xyz_lines = xyz_lines[HEADER_LENGTH + MAIN_MOLECULE_LENGTH: SECONDARY_MOLECULES_LENGTH]
|
||||||
|
|
||||||
input_file = Path(proc_dir, self.step.dice.outname + ".xy")
|
input_file = Path(proc_dir, self.step.dice.outname + ".xy")
|
||||||
with open(input_file, 'w') as f:
|
with open(input_file, 'w') as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user