Compare commits
26 Commits
v0.1.0
...
0470200d00
| Author | SHA1 | Date | |
|---|---|---|---|
|
0470200d00
|
|||
|
0763c4a9e1
|
|||
|
30be88e6b4
|
|||
|
6a154429e9
|
|||
|
4c8cbc821d
|
|||
|
9f22304dd8
|
|||
|
53eb34a83e
|
|||
|
06ae9b41f0
|
|||
|
11ff4c0c21
|
|||
|
c59f0d6516
|
|||
| 53f75b44a5 | |||
|
34e8758ff8
|
|||
|
2765e5b86c
|
|||
|
636c65c07c
|
|||
|
a5504b0435
|
|||
|
d400970e8f
|
|||
| b6e57bc1c5 | |||
|
cb4b21ab6c
|
|||
| 250dd4acf4 | |||
|
5d76e49f89
|
|||
| d89124b1e8 | |||
|
f0e5bbeaee
|
|||
|
c51d07cff2
|
|||
|
e5c6282c86
|
|||
| f56d6b6b36 | |||
|
0699791091
|
68
.github/workflows/python-test-and-build.yml
vendored
68
.github/workflows/python-test-and-build.yml
vendored
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
||||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
||||||
|
|
||||||
name: Upload DicePlayer to PyPI
|
name: build and upload
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push
|
push
|
||||||
@@ -13,24 +13,35 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version:
|
||||||
|
- "3.10"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install poetry
|
|
||||||
run: pipx install poetry
|
|
||||||
|
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.10
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
- name: Install uv
|
||||||
poetry self add "poetry-dynamic-versioning[plugin]"
|
uses: astral-sh/setup-uv@v5
|
||||||
if [ -f pyproject.toml ]; then poetry install; fi
|
with:
|
||||||
- name: Run unittest
|
# Install a specific version of uv.
|
||||||
run: |
|
version: "0.9.15"
|
||||||
poetry run python -m unittest
|
enable-cache: true
|
||||||
|
cache-dependency-glob: "uv.lock"
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: uv sync --all-extras --dev
|
||||||
|
|
||||||
|
- name: Run unittest
|
||||||
|
run: |
|
||||||
|
uv run python -m unittest
|
||||||
|
|
||||||
pypi-upload:
|
pypi-upload:
|
||||||
needs: [test]
|
needs: [test]
|
||||||
@@ -40,26 +51,27 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install poetry
|
|
||||||
run: pipx install poetry
|
|
||||||
|
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.10
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
- name: Install uv
|
||||||
poetry self add "poetry-dynamic-versioning[plugin]"
|
uses: astral-sh/setup-uv@v5
|
||||||
if [ -f pyproject.toml ]; then poetry install; fi
|
with:
|
||||||
- name: Build Python Package
|
# Install a specific version of uv.
|
||||||
run: |
|
version: "0.9.15"
|
||||||
poetry build -f sdist
|
enable-cache: true
|
||||||
poetry install
|
cache-dependency-glob: "uv.lock"
|
||||||
echo "Builded DicePlayer - $(poetry version)"
|
python-version: ${{ matrix.python-version }}
|
||||||
- name: Configure PyPI
|
|
||||||
run: |
|
- name: Install dependencies
|
||||||
poetry config repositories.pypi https://upload.pypi.org/legacy/
|
run: uv sync
|
||||||
poetry config pypi-token.pypi ${{secrets.PYPI_TOKEN}}
|
|
||||||
- name: Upload Python Package
|
- name: Build source distribution
|
||||||
run: |
|
run: uv build --sdist
|
||||||
poetry publish --repository pypi
|
|
||||||
|
- name: Upload Python Package
|
||||||
|
run: |
|
||||||
|
uv publish -t ${{ secrets.PYPI_TOKEN }}
|
||||||
184
.gitignore
vendored
184
.gitignore
vendored
@@ -1,20 +1,184 @@
|
|||||||
### Python ###
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
.vscode/settings.json
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# UV
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
#uv.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||||
|
.pdm.toml
|
||||||
|
.pdm-python
|
||||||
|
.pdm-build/
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# Ruff stuff:
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
|
# PyPI configuration file
|
||||||
|
.pypirc
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode
|
||||||
|
|
||||||
*.ljc
|
*.ljc
|
||||||
*.log
|
|
||||||
*.log.backup
|
*.log.backup
|
||||||
|
|
||||||
simfiles/*
|
simfiles/*
|
||||||
|
|
||||||
.vscode/*
|
|
||||||
.idea/*
|
|
||||||
*.pkl
|
*.pkl
|
||||||
|
|
||||||
*.xyz
|
*.xyz
|
||||||
|
|
||||||
dist/
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: 24.4.2
|
# Ruff version.
|
||||||
hooks:
|
rev: v0.14.7
|
||||||
- id: black
|
hooks:
|
||||||
args: [--config=pyproject.toml]
|
# Run the linter.
|
||||||
|
- id: ruff
|
||||||
- repo: https://github.com/pycqa/isort
|
# Run the formatter.
|
||||||
rev: 5.13.2
|
- id: ruff-format
|
||||||
hooks:
|
|
||||||
- id: isort
|
|
||||||
files: "\\.(py)$"
|
|
||||||
args: [--settings-path=pyproject.toml]
|
|
||||||
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.12
|
||||||
@@ -1,23 +1,25 @@
|
|||||||
diceplayer:
|
diceplayer:
|
||||||
opt: no
|
type: both
|
||||||
|
switch_cyc: 3
|
||||||
|
max_cyc: 5
|
||||||
mem: 24
|
mem: 24
|
||||||
maxcyc: 5
|
ncores: 20
|
||||||
ncores: 5
|
|
||||||
nprocs: 4
|
|
||||||
qmprog: 'g16'
|
qmprog: 'g16'
|
||||||
lps: no
|
lps: no
|
||||||
ghosts: no
|
ghosts: no
|
||||||
altsteps: 2000
|
altsteps: 2000
|
||||||
|
|
||||||
dice:
|
dice:
|
||||||
nmol: [1, 100]
|
nprocs: 1
|
||||||
|
nmol: [1, 200]
|
||||||
dens: 1.5
|
dens: 1.5
|
||||||
nstep: [2000, 3000]
|
nstep: [200, 300]
|
||||||
isave: 1000
|
isave: 100
|
||||||
outname: 'phb'
|
outname: 'phb'
|
||||||
progname: '~/.local/bin/dice'
|
progname: 'dice'
|
||||||
ljname: 'phb.ljc'
|
ljname: 'phb.ljc.example'
|
||||||
randominit: 'always'
|
randominit: 'always'
|
||||||
|
seed: 12345
|
||||||
|
|
||||||
gaussian:
|
gaussian:
|
||||||
qmprog: 'g16'
|
qmprog: 'g16'
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
from diceplayer.shared.utils.logger import Logger
|
|
||||||
|
|
||||||
from importlib import metadata
|
|
||||||
|
|
||||||
VERSION = metadata.version("diceplayer")
|
|
||||||
|
|
||||||
logger = Logger(__name__)
|
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
from diceplayer import VERSION, logger
|
from diceplayer.cli import ArgsModel, read_input
|
||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.logger import logger
|
||||||
from diceplayer.player import Player
|
from diceplayer.player import Player
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
from importlib import metadata
|
||||||
|
|
||||||
|
|
||||||
|
VERSION = metadata.version("diceplayer")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
|
||||||
Read and store the arguments passed to the program
|
|
||||||
and set the usage and help messages
|
|
||||||
"""
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog="Diceplayer")
|
parser = argparse.ArgumentParser(prog="Diceplayer")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-c", "--continue", dest="opt_continue", default=False, action="store_true"
|
"-v", "--version", action="version", version="diceplayer-" + VERSION
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--version", action="version", version="diceplayer-" + VERSION
|
"-c", "--continue", dest="continuation", default=False, action="store_true"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-i",
|
"-i",
|
||||||
@@ -34,36 +34,26 @@ def main():
|
|||||||
metavar="OUTFILE",
|
metavar="OUTFILE",
|
||||||
help="output file of diceplayer [default = run.log]",
|
help="output file of diceplayer [default = run.log]",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
parser.add_argument(
|
||||||
|
"-f",
|
||||||
|
"--force",
|
||||||
|
dest="force",
|
||||||
|
default=False,
|
||||||
|
action="store_true",
|
||||||
|
help="force overwrite existing state file if it exists [default = False]",
|
||||||
|
)
|
||||||
|
args = ArgsModel.from_args(parser.parse_args())
|
||||||
|
|
||||||
# Open OUTFILE for writing and print keywords and initial info
|
logger.set_output_file(args.outfile)
|
||||||
logger.set_logger(args.outfile, logging.INFO)
|
|
||||||
|
|
||||||
if args.opt_continue:
|
config: PlayerConfig
|
||||||
player = Player.from_save()
|
try:
|
||||||
else:
|
config = read_input(args.infile)
|
||||||
player = Player.from_file(args.infile)
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to read input file: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
player.read_potentials()
|
Player(config).play(continuation=args.continuation, force=args.force)
|
||||||
|
|
||||||
player.create_simulation_dir()
|
|
||||||
player.create_geoms_file()
|
|
||||||
|
|
||||||
player.print_keywords()
|
|
||||||
|
|
||||||
player.print_potentials()
|
|
||||||
|
|
||||||
player.prepare_system()
|
|
||||||
|
|
||||||
player.start()
|
|
||||||
|
|
||||||
logger.info("\n+" + 88 * "-" + "+\n")
|
|
||||||
|
|
||||||
player.print_results()
|
|
||||||
|
|
||||||
logger.info("\n+" + 88 * "-" + "+\n")
|
|
||||||
|
|
||||||
logger.info("Diceplayer finished successfully \n")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
5
diceplayer/cli/__init__.py
Normal file
5
diceplayer/cli/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from .args_model import ArgsModel
|
||||||
|
from .read_input_file import read_input
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["ArgsModel", "read_input"]
|
||||||
12
diceplayer/cli/args_model.py
Normal file
12
diceplayer/cli/args_model.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ArgsModel(BaseModel):
|
||||||
|
outfile: str
|
||||||
|
infile: str
|
||||||
|
continuation: bool
|
||||||
|
force: bool
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_args(cls, args):
|
||||||
|
return cls(**vars(args))
|
||||||
9
diceplayer/cli/read_input_file.py
Normal file
9
diceplayer/cli/read_input_file.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def read_input(infile) -> PlayerConfig:
|
||||||
|
with open(infile, "r") as f:
|
||||||
|
values = yaml.safe_load(f)
|
||||||
|
return PlayerConfig.model_validate(values["diceplayer"])
|
||||||
10
diceplayer/config/__init__.py
Normal file
10
diceplayer/config/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from .dice_config import DiceConfig
|
||||||
|
from .gaussian_config import GaussianConfig
|
||||||
|
from .player_config import PlayerConfig
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"DiceConfig",
|
||||||
|
"GaussianConfig",
|
||||||
|
"PlayerConfig",
|
||||||
|
]
|
||||||
60
diceplayer/config/dice_config.py
Normal file
60
diceplayer/config/dice_config.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
import random
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class DiceConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Data Transfer Object for the Dice configuration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
model_config = ConfigDict(
|
||||||
|
frozen=True,
|
||||||
|
)
|
||||||
|
nprocs: int = Field(
|
||||||
|
..., description="Number of processes to use for the DICE simulations"
|
||||||
|
)
|
||||||
|
|
||||||
|
ljname: Path = Field(..., description="Name of the Lennard-Jones potential file")
|
||||||
|
outname: str = Field(
|
||||||
|
..., description="Name of the output file for the simulation results"
|
||||||
|
)
|
||||||
|
dens: float = Field(..., description="Density of the system")
|
||||||
|
nmol: list[int] = Field(
|
||||||
|
..., description="List of the number of molecules for each component"
|
||||||
|
)
|
||||||
|
nstep: list[int] = Field(
|
||||||
|
...,
|
||||||
|
description="List of the number of steps for each component",
|
||||||
|
min_length=2,
|
||||||
|
max_length=3,
|
||||||
|
)
|
||||||
|
|
||||||
|
upbuf: int = Field(
|
||||||
|
360, description="Buffer size for the potential energy calculations"
|
||||||
|
)
|
||||||
|
irdf: int = Field(
|
||||||
|
0,
|
||||||
|
description="Controls the interval of Monte Carlo steps at which configurations are used at computation of radial distribution functions",
|
||||||
|
)
|
||||||
|
vstep: int = Field(
|
||||||
|
5000, description="Frequency of volume change moves in NPT simulations"
|
||||||
|
)
|
||||||
|
combrule: Literal["+", "*"] = Field(
|
||||||
|
"*", description="Combination rule for the Lennard-Jones potential"
|
||||||
|
)
|
||||||
|
isave: int = Field(1000, description="Frequency of saving the simulation results")
|
||||||
|
press: float = Field(1.0, description="Pressure of the system")
|
||||||
|
temp: float = Field(300.0, description="Temperature of the system")
|
||||||
|
progname: str = Field(
|
||||||
|
"dice", description="Name of the program to run the simulation"
|
||||||
|
)
|
||||||
|
randominit: str = Field(
|
||||||
|
"first", description="Method for initializing the random number generator"
|
||||||
|
)
|
||||||
|
seed: int = Field(
|
||||||
|
default_factory=lambda: int(1e6 * random.random()),
|
||||||
|
description="Seed for the random number generator",
|
||||||
|
)
|
||||||
29
diceplayer/config/gaussian_config.py
Normal file
29
diceplayer/config/gaussian_config.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
|
||||||
|
class GaussianConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Data Transfer Object for the Gaussian configuration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
model_config = ConfigDict(
|
||||||
|
frozen=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
qmprog: Literal["g03", "g09", "g16"] = Field(
|
||||||
|
"g16", description="QM program to use for the calculations"
|
||||||
|
)
|
||||||
|
level: str = Field(..., description="Level of theory for the QM calculations")
|
||||||
|
|
||||||
|
chgmult: list[int] = Field(
|
||||||
|
default_factory=lambda: [0, 1],
|
||||||
|
description="List of charge and multiplicity for the QM calculations",
|
||||||
|
)
|
||||||
|
pop: str = Field(
|
||||||
|
"chelpg", description="Population analysis method for the QM calculations"
|
||||||
|
)
|
||||||
|
chg_tol: float = Field(0.01, description="Charge tolerance for the QM calculations")
|
||||||
|
keywords: str | None = Field(
|
||||||
|
None, description="Additional keywords for the QM calculations"
|
||||||
|
)
|
||||||
90
diceplayer/config/player_config.py
Normal file
90
diceplayer/config/player_config.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
from diceplayer.config.dice_config import DiceConfig
|
||||||
|
from diceplayer.config.gaussian_config import GaussianConfig
|
||||||
|
|
||||||
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||||
|
from typing_extensions import Any
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
MIN_STEP = 20000
|
||||||
|
STEP_INCREMENT = 1000
|
||||||
|
|
||||||
|
|
||||||
|
class RoutineType(str, Enum):
|
||||||
|
CHARGE = "charge"
|
||||||
|
GEOMETRY = "geometry"
|
||||||
|
BOTH = "both"
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Configuration for DICEPlayer simulations.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
type: Type of simulation to perform (charge, geometry, or both).
|
||||||
|
max_cyc: Maximum number of cycles for the geometry optimization.
|
||||||
|
switch_cyc: Cycle at which to switch from charge to geometry optimization (if type is "both").
|
||||||
|
mem: Memory configuration for QM calculations.
|
||||||
|
nprocs: Number of processors to use for QM calculations.
|
||||||
|
ncores: Number of cores to use for QM calculations.
|
||||||
|
dice: Configuration parameters specific to DICE simulations.
|
||||||
|
gaussian: Configuration parameters specific to Gaussian calculations.
|
||||||
|
altsteps: Number of steps for the alternate simulation (default: 20000).
|
||||||
|
geoms_file: File name for the geometries output (default: "geoms.xyz").
|
||||||
|
simulation_dir: Directory name for the simulation files (default: "simfiles").
|
||||||
|
"""
|
||||||
|
|
||||||
|
model_config = ConfigDict(
|
||||||
|
frozen=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
type: RoutineType = Field(..., description="Type of simulation to perform")
|
||||||
|
max_cyc: int = Field(
|
||||||
|
..., description="Maximum number of cycles for the geometry optimization", gt=0
|
||||||
|
)
|
||||||
|
switch_cyc: int = Field(..., description="Switch cycle configuration")
|
||||||
|
|
||||||
|
mem: int = Field(None, description="Memory configuration")
|
||||||
|
ncores: int = Field(
|
||||||
|
..., description="Number of cores to use for the QM calculations"
|
||||||
|
)
|
||||||
|
|
||||||
|
dice: DiceConfig = Field(..., description="Dice configuration")
|
||||||
|
gaussian: GaussianConfig = Field(..., description="Gaussian configuration")
|
||||||
|
|
||||||
|
altsteps: int = Field(
|
||||||
|
20000, description="Number of steps for the alternate simulation"
|
||||||
|
)
|
||||||
|
geoms_file: Path = Field(
|
||||||
|
Path("geoms.xyz"), description="File name for the geometries output"
|
||||||
|
)
|
||||||
|
simulation_dir: Path = Field(
|
||||||
|
Path("simfiles"), description="Directory name for the simulation files"
|
||||||
|
)
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@staticmethod
|
||||||
|
def validate_altsteps(fields) -> dict[str, Any]:
|
||||||
|
altsteps = fields.pop("altsteps", MIN_STEP)
|
||||||
|
fields["altsteps"] = (
|
||||||
|
round(max(MIN_STEP, altsteps) / STEP_INCREMENT) * STEP_INCREMENT
|
||||||
|
)
|
||||||
|
return fields
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@staticmethod
|
||||||
|
def validate_switch_cyc(fields: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
max_cyc = int(fields.get("max_cyc", 0))
|
||||||
|
switch_cyc = int(fields.get("switch_cyc", max_cyc))
|
||||||
|
|
||||||
|
if fields.get("type") == "both" and not switch_cyc < max_cyc:
|
||||||
|
raise ValueError("switch_cyc must be less than max_cyc when type='both'.")
|
||||||
|
|
||||||
|
if fields.get("type") != "both" and switch_cyc != max_cyc:
|
||||||
|
raise ValueError(
|
||||||
|
"switch_cyc must be equal to max_cyc when type is not 'both'."
|
||||||
|
)
|
||||||
|
|
||||||
|
return fields
|
||||||
174
diceplayer/dice/__init__.py
Normal file
174
diceplayer/dice/__init__.py
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
"""
|
||||||
|
DICE Monte Carlo Simulation Interface
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
This package provides utilities for configuring and running simulations with
|
||||||
|
the DICE Monte Carlo molecular simulation program.
|
||||||
|
|
||||||
|
DICE performs statistical sampling of molecular systems using the Metropolis
|
||||||
|
Monte Carlo algorithm. Simulations are defined by text input files containing
|
||||||
|
keywords that control the thermodynamic ensemble, system composition, and
|
||||||
|
simulation parameters.
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
Simulation Ensembles
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
DICE supports multiple statistical ensembles.
|
||||||
|
|
||||||
|
NVT
|
||||||
|
Canonical ensemble where the following properties remain constant:
|
||||||
|
|
||||||
|
- N: number of molecules
|
||||||
|
- V: system volume
|
||||||
|
- T: temperature
|
||||||
|
|
||||||
|
The system density is fixed and the simulation box volume does not change
|
||||||
|
during the simulation.
|
||||||
|
|
||||||
|
NPT
|
||||||
|
Isothermal–isobaric ensemble where the following properties remain constant:
|
||||||
|
|
||||||
|
- N: number of molecules
|
||||||
|
- P: pressure
|
||||||
|
- T: temperature
|
||||||
|
|
||||||
|
The simulation box volume is allowed to fluctuate in order to maintain the
|
||||||
|
target pressure.
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
Simulation Stages
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Simulations are typically executed in multiple stages.
|
||||||
|
|
||||||
|
Thermalization (TER)
|
||||||
|
Initial phase where the system relaxes to the desired thermodynamic
|
||||||
|
conditions. Molecular configurations stabilize and the system reaches
|
||||||
|
equilibrium.
|
||||||
|
|
||||||
|
During this stage statistical properties are **not accumulated**.
|
||||||
|
|
||||||
|
Production / Equilibration (EQ)
|
||||||
|
Main sampling phase after the system has equilibrated.
|
||||||
|
|
||||||
|
Statistical properties such as energies, densities, and radial
|
||||||
|
distribution functions are collected and configurations may be saved
|
||||||
|
for later analysis.
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
Typical Simulation Pipeline
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
Two common execution workflows are used.
|
||||||
|
|
||||||
|
NVT Simulation
|
||||||
|
Used when the system density is known.
|
||||||
|
|
||||||
|
1. NVT.ter → thermalization at constant density
|
||||||
|
2. NVT.eq → production sampling
|
||||||
|
|
||||||
|
NPT Simulation
|
||||||
|
Used when the equilibrium density is unknown.
|
||||||
|
|
||||||
|
1. NVT.ter → initial thermalization at approximate density
|
||||||
|
2. NPT.ter → pressure relaxation (volume adjustment)
|
||||||
|
3. NPT.eq → production sampling at target pressure
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
DICE Input Keywords
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
The following keywords are used in the generated input files.
|
||||||
|
|
||||||
|
title
|
||||||
|
Descriptive title printed in the simulation output.
|
||||||
|
|
||||||
|
ncores
|
||||||
|
Number of CPU cores used by the DICE executable.
|
||||||
|
|
||||||
|
ljname
|
||||||
|
File containing Lennard-Jones parameters and molecular topology.
|
||||||
|
|
||||||
|
outname
|
||||||
|
Prefix used for simulation output files.
|
||||||
|
|
||||||
|
nmol
|
||||||
|
Number of molecules of each species in the system.
|
||||||
|
|
||||||
|
dens
|
||||||
|
System density (g/cm³). Used only in NVT simulations or for
|
||||||
|
initialization of NPT runs.
|
||||||
|
|
||||||
|
press
|
||||||
|
Target pressure used in NPT simulations.
|
||||||
|
|
||||||
|
temp
|
||||||
|
Simulation temperature.
|
||||||
|
|
||||||
|
nstep
|
||||||
|
Number of Monte Carlo cycles executed in the simulation stage.
|
||||||
|
|
||||||
|
init
|
||||||
|
Defines how the simulation initializes molecular coordinates.
|
||||||
|
|
||||||
|
yes
|
||||||
|
Random initial configuration.
|
||||||
|
|
||||||
|
no
|
||||||
|
Continue from a previous configuration.
|
||||||
|
|
||||||
|
yesreadxyz
|
||||||
|
Read coordinates from a previously saved XYZ configuration.
|
||||||
|
|
||||||
|
vstep
|
||||||
|
Frequency of volume-change moves in NPT simulations.
|
||||||
|
|
||||||
|
mstop
|
||||||
|
Molecule displacement control flag used internally by DICE.
|
||||||
|
|
||||||
|
accum
|
||||||
|
Enables or disables accumulation of statistical averages.
|
||||||
|
|
||||||
|
iprint
|
||||||
|
Frequency of simulation information printed to the output.
|
||||||
|
|
||||||
|
isave
|
||||||
|
Frequency at which configurations are written to trajectory files.
|
||||||
|
|
||||||
|
irdf
|
||||||
|
Controls calculation of radial distribution functions.
|
||||||
|
|
||||||
|
seed
|
||||||
|
Random number generator seed used by the Monte Carlo algorithm.
|
||||||
|
|
||||||
|
upbuf
|
||||||
|
Buffer size parameter used internally by DICE during thermalization.
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
Output Files
|
||||||
|
------------
|
||||||
|
|
||||||
|
Important output files produced during the simulation include:
|
||||||
|
|
||||||
|
phb.xyz
|
||||||
|
XYZ trajectory containing sampled molecular configurations.
|
||||||
|
|
||||||
|
last.xyz
|
||||||
|
Final configuration of the simulation, often used as the starting
|
||||||
|
configuration for the next simulation cycle.
|
||||||
|
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
References
|
||||||
|
----------
|
||||||
|
|
||||||
|
DICE is a Monte Carlo molecular simulation program developed primarily
|
||||||
|
by researchers at the University of São Paulo (USP) for studying liquids,
|
||||||
|
solutions, and solvation phenomena.
|
||||||
|
"""
|
||||||
115
diceplayer/dice/dice_handler.py
Normal file
115
diceplayer/dice/dice_handler.py
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
from diceplayer.dice.dice_input import (
|
||||||
|
NPTEqConfig,
|
||||||
|
NPTTerConfig,
|
||||||
|
NVTEqConfig,
|
||||||
|
NVTTerConfig,
|
||||||
|
)
|
||||||
|
from diceplayer.dice.dice_wrapper import DiceWrapper
|
||||||
|
from diceplayer.logger import logger
|
||||||
|
from diceplayer.state.state_model import StateModel
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
|
||||||
|
class DiceHandler:
|
||||||
|
def __init__(self, step_directory: Path):
|
||||||
|
self.dice_directory = step_directory / "dice"
|
||||||
|
|
||||||
|
def run(self, state: StateModel, cycle: int) -> StateModel:
|
||||||
|
if self.dice_directory.exists():
|
||||||
|
logger.info(
|
||||||
|
f"Found dice directory: {self.dice_directory}, this directory will be purged for a clean state"
|
||||||
|
)
|
||||||
|
shutil.rmtree(self.dice_directory)
|
||||||
|
self.dice_directory.mkdir(parents=True)
|
||||||
|
|
||||||
|
simulation_results = self.run_simulations(state, cycle)
|
||||||
|
|
||||||
|
result = self.aggregate_results(simulation_results)
|
||||||
|
|
||||||
|
return self.commit_simulation_state(state, result)
|
||||||
|
|
||||||
|
def run_simulations(self, state: StateModel, cycle: int) -> list[dict]:
|
||||||
|
results = []
|
||||||
|
|
||||||
|
threads = []
|
||||||
|
for p in range(state.config.dice.nprocs):
|
||||||
|
t = Thread(target=self._simulation_process, args=(state, cycle, p, results))
|
||||||
|
threads.append(t)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
for t in threads:
|
||||||
|
t.join()
|
||||||
|
|
||||||
|
if len(results) != state.config.dice.nprocs:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Expected {state.config.dice.nprocs} simulation results, but got {len(results)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def aggregate_results(self, simulation_results: list[dict]) -> dict: ...
|
||||||
|
|
||||||
|
def commit_simulation_state(self, state: StateModel, result: dict) -> StateModel:
|
||||||
|
return state
|
||||||
|
|
||||||
|
def _simulation_process(
|
||||||
|
self, state: StateModel, cycle: int, proc: int, results: list[dict]
|
||||||
|
) -> None:
|
||||||
|
proc_directory = self.dice_directory / f"{proc:02d}"
|
||||||
|
if proc_directory.exists():
|
||||||
|
shutil.rmtree(proc_directory)
|
||||||
|
proc_directory.mkdir(parents=True)
|
||||||
|
|
||||||
|
dice = DiceWrapper(state.config.dice, proc_directory)
|
||||||
|
|
||||||
|
self._generate_phb_file(state, proc_directory)
|
||||||
|
|
||||||
|
if state.config.dice.randominit == "first" and cycle >= 0:
|
||||||
|
self._generate_last_xyz(state, proc_directory)
|
||||||
|
else:
|
||||||
|
nvt_ter_config = NVTTerConfig.from_config(state.config)
|
||||||
|
dice.run(nvt_ter_config)
|
||||||
|
|
||||||
|
if len(state.config.dice.nstep) == 2:
|
||||||
|
nvt_eq_config = NVTEqConfig.from_config(state.config)
|
||||||
|
dice.run(nvt_eq_config)
|
||||||
|
|
||||||
|
elif len(state.config.dice.nstep) == 3:
|
||||||
|
npt_ter_config = NPTTerConfig.from_config(state.config)
|
||||||
|
dice.run(npt_ter_config)
|
||||||
|
|
||||||
|
npt_eq_config = NPTEqConfig.from_config(state.config)
|
||||||
|
dice.run(npt_eq_config)
|
||||||
|
|
||||||
|
results.append(dice.parse_results(state.system))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _generate_phb_file(state: StateModel, proc_directory: Path) -> None:
|
||||||
|
fstr = "{:<3d} {:>3d} {:>10.5f} {:>10.5f} {:>10.5f} {:>10.6f} {:>9.5f} {:>7.4f}\n"
|
||||||
|
|
||||||
|
phb_file = proc_directory / state.config.dice.ljname
|
||||||
|
|
||||||
|
with open(phb_file, "w") as f:
|
||||||
|
f.write(f"{state.config.dice.combrule}\n")
|
||||||
|
f.write(f"{len(state.config.dice.nmol)}\n")
|
||||||
|
|
||||||
|
for molecule in state.system.molecule:
|
||||||
|
f.write(f"{len(molecule.atom)} {molecule.molname}\n")
|
||||||
|
for atom in molecule.atom:
|
||||||
|
f.write(
|
||||||
|
fstr.format(
|
||||||
|
atom.lbl,
|
||||||
|
atom.na,
|
||||||
|
atom.rx,
|
||||||
|
atom.ry,
|
||||||
|
atom.rz,
|
||||||
|
atom.chg,
|
||||||
|
atom.eps,
|
||||||
|
atom.sig,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _generate_last_xyz(self, state: StateModel, proc_directory: Path) -> None: ...
|
||||||
257
diceplayer/dice/dice_input.py
Normal file
257
diceplayer/dice/dice_input.py
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.logger import logger
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
|
import random
|
||||||
|
from enum import StrEnum
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Annotated, Any, Literal, TextIO
|
||||||
|
|
||||||
|
|
||||||
|
_ALLOWED_DICE_KEYWORD_IN_ORDER = [
|
||||||
|
"title",
|
||||||
|
"ncores",
|
||||||
|
"ljname",
|
||||||
|
"outname",
|
||||||
|
"nmol",
|
||||||
|
"dens",
|
||||||
|
"temp",
|
||||||
|
"press",
|
||||||
|
"seed",
|
||||||
|
"init",
|
||||||
|
"nstep",
|
||||||
|
"vstep",
|
||||||
|
"mstop",
|
||||||
|
"accum",
|
||||||
|
"iprint",
|
||||||
|
"isave",
|
||||||
|
"irdf",
|
||||||
|
"upbuf",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class DiceRoutineType(StrEnum):
|
||||||
|
NVT_TER = "nvt.ter"
|
||||||
|
NVT_EQ = "nvt.eq"
|
||||||
|
NPT_TER = "npt.ter"
|
||||||
|
NPT_EQ = "npt.eq"
|
||||||
|
|
||||||
|
|
||||||
|
def get_nstep(config, idx: int) -> int:
|
||||||
|
if len(config.dice.nstep) > idx:
|
||||||
|
return config.dice.nstep[idx]
|
||||||
|
return config.dice.nstep[-1]
|
||||||
|
|
||||||
|
|
||||||
|
def get_seed(config) -> int:
|
||||||
|
return config.dice.seed or random.randint(0, 2**32 - 1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_ncores(config) -> int:
|
||||||
|
return max(1, int(config.ncores / config.dice.nprocs))
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# NVT THERMALIZATION
|
||||||
|
# -----------------------------------------------------
|
||||||
|
class NVTTerConfig(BaseModel):
|
||||||
|
type: Literal[DiceRoutineType.NVT_TER] = DiceRoutineType.NVT_TER
|
||||||
|
|
||||||
|
title: str = "NVT Thermalization"
|
||||||
|
ncores: int
|
||||||
|
ljname: str
|
||||||
|
outname: str
|
||||||
|
nmol: list[int]
|
||||||
|
dens: float
|
||||||
|
temp: float
|
||||||
|
seed: int
|
||||||
|
init: Literal["yes"] = "yes"
|
||||||
|
nstep: int
|
||||||
|
vstep: Literal[0] = 0
|
||||||
|
isave: int
|
||||||
|
upbuf: int
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, config: PlayerConfig, **kwargs) -> Self:
|
||||||
|
return cls(
|
||||||
|
ncores=get_ncores(config),
|
||||||
|
ljname=str(config.dice.ljname),
|
||||||
|
outname=config.dice.outname,
|
||||||
|
nmol=config.dice.nmol,
|
||||||
|
dens=config.dice.dens,
|
||||||
|
temp=config.dice.temp,
|
||||||
|
seed=get_seed(config),
|
||||||
|
nstep=get_nstep(config, 0),
|
||||||
|
isave=config.dice.isave,
|
||||||
|
upbuf=config.dice.upbuf,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# NVT PRODUCTION
|
||||||
|
# -----------------------------------------------------
|
||||||
|
class NVTEqConfig(BaseModel):
|
||||||
|
type: Literal[DiceRoutineType.NVT_EQ] = DiceRoutineType.NVT_EQ
|
||||||
|
|
||||||
|
title: str = "NVT Production"
|
||||||
|
ncores: int
|
||||||
|
ljname: str
|
||||||
|
outname: str
|
||||||
|
nmol: list[int]
|
||||||
|
dens: float
|
||||||
|
temp: float
|
||||||
|
seed: int
|
||||||
|
init: Literal["no", "yesreadxyz"] = "no"
|
||||||
|
nstep: int
|
||||||
|
vstep: int
|
||||||
|
isave: int
|
||||||
|
irdf: Literal[0] = 0
|
||||||
|
upbuf: int
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, config: PlayerConfig, **kwargs) -> Self:
|
||||||
|
return cls(
|
||||||
|
ncores=get_ncores(config),
|
||||||
|
ljname=str(config.dice.ljname),
|
||||||
|
outname=config.dice.outname,
|
||||||
|
nmol=config.dice.nmol,
|
||||||
|
dens=config.dice.dens,
|
||||||
|
temp=config.dice.temp,
|
||||||
|
seed=get_seed(config),
|
||||||
|
nstep=get_nstep(config, 1),
|
||||||
|
vstep=config.dice.vstep,
|
||||||
|
isave=max(1, get_nstep(config, 1) // 10),
|
||||||
|
upbuf=config.dice.upbuf,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# NPT THERMALIZATION
|
||||||
|
# -----------------------------------------------------
|
||||||
|
class NPTTerConfig(BaseModel):
|
||||||
|
type: Literal[DiceRoutineType.NPT_TER] = DiceRoutineType.NPT_TER
|
||||||
|
|
||||||
|
title: str = "NPT Thermalization"
|
||||||
|
ncores: int
|
||||||
|
ljname: str
|
||||||
|
outname: str
|
||||||
|
nmol: list[int]
|
||||||
|
dens: float
|
||||||
|
temp: float
|
||||||
|
press: float
|
||||||
|
seed: int
|
||||||
|
init: Literal["yes", "yesreadxyz"] = "yes"
|
||||||
|
nstep: int
|
||||||
|
vstep: int
|
||||||
|
isave: int
|
||||||
|
upbuf: int
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, config: PlayerConfig, **kwargs) -> Self:
|
||||||
|
return cls(
|
||||||
|
ncores=get_ncores(config),
|
||||||
|
ljname=str(config.dice.ljname),
|
||||||
|
outname=config.dice.outname,
|
||||||
|
nmol=config.dice.nmol,
|
||||||
|
dens=config.dice.dens,
|
||||||
|
temp=config.dice.temp,
|
||||||
|
press=config.dice.press,
|
||||||
|
seed=get_seed(config),
|
||||||
|
nstep=get_nstep(config, 1),
|
||||||
|
vstep=max(1, config.dice.vstep),
|
||||||
|
isave=config.dice.isave,
|
||||||
|
upbuf=config.dice.upbuf,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# NPT PRODUCTION
|
||||||
|
# -----------------------------------------------------
|
||||||
|
class NPTEqConfig(BaseModel):
|
||||||
|
type: Literal[DiceRoutineType.NPT_EQ] = DiceRoutineType.NPT_EQ
|
||||||
|
|
||||||
|
title: str = "NPT Production"
|
||||||
|
ncores: int
|
||||||
|
ljname: str
|
||||||
|
outname: str
|
||||||
|
nmol: list[int]
|
||||||
|
dens: float
|
||||||
|
temp: float
|
||||||
|
press: float
|
||||||
|
seed: int
|
||||||
|
init: Literal["yes", "yesreadxyz"] = "yes"
|
||||||
|
nstep: int
|
||||||
|
vstep: int
|
||||||
|
isave: int
|
||||||
|
irdf: Literal[0] = 0
|
||||||
|
upbuf: int
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, config: PlayerConfig, **kwargs) -> Self:
|
||||||
|
return cls(
|
||||||
|
ncores=get_ncores(config),
|
||||||
|
ljname=str(config.dice.ljname),
|
||||||
|
outname=config.dice.outname,
|
||||||
|
nmol=config.dice.nmol,
|
||||||
|
dens=config.dice.dens,
|
||||||
|
temp=config.dice.temp,
|
||||||
|
press=config.dice.press,
|
||||||
|
seed=get_seed(config),
|
||||||
|
nstep=get_nstep(config, 2),
|
||||||
|
vstep=config.dice.vstep,
|
||||||
|
isave=max(1, get_nstep(config, 2) // 10),
|
||||||
|
upbuf=config.dice.upbuf,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
DiceInputConfig = Annotated[
|
||||||
|
NVTTerConfig | NVTEqConfig | NPTTerConfig | NPTEqConfig,
|
||||||
|
Field(discriminator="type"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _serialize_value(value: Any) -> str:
|
||||||
|
if value is None:
|
||||||
|
raise ValueError("DICE configuration cannot serialize None values")
|
||||||
|
|
||||||
|
if isinstance(value, bool):
|
||||||
|
return "yes" if value else "no"
|
||||||
|
|
||||||
|
if isinstance(value, (list, tuple)):
|
||||||
|
return " ".join(str(v) for v in value)
|
||||||
|
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
def write_dice_config(obj: DiceInputConfig, io_writer: TextIO) -> None:
|
||||||
|
values = {f: getattr(obj, f) for f in obj.__class__.model_fields}
|
||||||
|
|
||||||
|
for key in _ALLOWED_DICE_KEYWORD_IN_ORDER:
|
||||||
|
value = values.pop(key, None)
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
io_writer.write(f"{key} = {_serialize_value(value)}\n")
|
||||||
|
|
||||||
|
io_writer.write("$end\n")
|
||||||
|
|
||||||
|
|
||||||
|
def write_config(config: DiceInputConfig, directory: Path) -> Path:
|
||||||
|
input_path = directory / config.type
|
||||||
|
|
||||||
|
if input_path.exists():
|
||||||
|
logger.info(
|
||||||
|
f"Dice input file {input_path} already exists and will be overwritten"
|
||||||
|
)
|
||||||
|
input_path.unlink()
|
||||||
|
input_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
with open(input_path, "w") as io:
|
||||||
|
write_dice_config(config, io)
|
||||||
|
|
||||||
|
return input_path
|
||||||
43
diceplayer/dice/dice_wrapper.py
Normal file
43
diceplayer/dice/dice_wrapper.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import diceplayer.dice.dice_input as dice_input
|
||||||
|
from diceplayer.config import DiceConfig
|
||||||
|
from diceplayer.environment import System
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
|
|
||||||
|
DICE_FLAG_LINE: Final[int] = -2
|
||||||
|
DICE_END_FLAG: Final[str] = "End of simulation"
|
||||||
|
|
||||||
|
|
||||||
|
class DiceWrapper:
|
||||||
|
def __init__(self, dice_config: DiceConfig, working_directory: Path):
|
||||||
|
self.dice_config = dice_config
|
||||||
|
self.working_directory = working_directory
|
||||||
|
|
||||||
|
def run(self, dice_config: dice_input.DiceInputConfig) -> None:
|
||||||
|
input_path = dice_input.write_config(dice_config, self.working_directory)
|
||||||
|
output_path = input_path.parent / (input_path.name + ".out")
|
||||||
|
|
||||||
|
with open(output_path, "w") as outfile, open(input_path, "r") as infile:
|
||||||
|
exit_status = subprocess.call(
|
||||||
|
self.dice_config.progname, stdin=infile, stdout=outfile, cwd=self.working_directory
|
||||||
|
)
|
||||||
|
|
||||||
|
if exit_status != 0:
|
||||||
|
raise RuntimeError(f"Dice simulation failed with exit status {exit_status}")
|
||||||
|
|
||||||
|
with open(output_path, "r") as outfile:
|
||||||
|
line = outfile.readlines()[DICE_FLAG_LINE]
|
||||||
|
if line.strip() == DICE_END_FLAG:
|
||||||
|
return
|
||||||
|
|
||||||
|
raise RuntimeError(f"Dice simulation failed with exit status {exit_status}")
|
||||||
|
|
||||||
|
def parse_results(self, system: System) -> dict:
|
||||||
|
results = {}
|
||||||
|
for output_file in sorted(self.working_directory.glob("phb*.xyz")):
|
||||||
|
...
|
||||||
|
|
||||||
|
return results
|
||||||
6
diceplayer/environment/__init__.py
Normal file
6
diceplayer/environment/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from .atom import Atom
|
||||||
|
from .molecule import Molecule
|
||||||
|
from .system import System
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["Atom", "Molecule", "System"]
|
||||||
27
diceplayer/environment/atom.py
Normal file
27
diceplayer/environment/atom.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from diceplayer.utils.ptable import AtomInfo, PTable
|
||||||
|
|
||||||
|
from pydantic.dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(slots=True)
|
||||||
|
class Atom:
|
||||||
|
"""
|
||||||
|
Atom class declaration. This class is used throughout the DicePlayer program to represent atoms.
|
||||||
|
"""
|
||||||
|
|
||||||
|
lbl: int
|
||||||
|
na: int
|
||||||
|
rx: float
|
||||||
|
ry: float
|
||||||
|
rz: float
|
||||||
|
chg: float
|
||||||
|
eps: float
|
||||||
|
sig: float
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mass(self) -> float:
|
||||||
|
return PTable.get_atomic_mass(self.na)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def atom_info(self) -> AtomInfo:
|
||||||
|
return PTable.get_from_atomic_number(self.na)
|
||||||
317
diceplayer/environment/molecule.py
Normal file
317
diceplayer/environment/molecule.py
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from diceplayer.environment import Atom
|
||||||
|
from diceplayer.logger import logger
|
||||||
|
from diceplayer.utils.cache import invalidate_computed_properties
|
||||||
|
from diceplayer.utils.misc import BOHR2ANG, EA_2_DEBYE
|
||||||
|
from diceplayer.utils.ptable import GHOST_NUMBER
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import numpy.linalg as linalg
|
||||||
|
import numpy.typing as npt
|
||||||
|
from pydantic.dataclasses import dataclass
|
||||||
|
from typing_extensions import List, Self, Tuple
|
||||||
|
|
||||||
|
import math
|
||||||
|
from copy import deepcopy
|
||||||
|
from dataclasses import field
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Molecule:
|
||||||
|
"""
|
||||||
|
Molecule class declaration. This class is used throughout the DicePlayer program to represent molecules.
|
||||||
|
|
||||||
|
Atributes:
|
||||||
|
molname (str): The name of the represented molecule
|
||||||
|
atom (List[Atom]): List of atoms of the represented molecule
|
||||||
|
total_mass (int): The total mass of the molecule
|
||||||
|
com (npt.NDArray[np.float64]): The center of mass of the molecule
|
||||||
|
inertia_tensor (npt.NDArray[np.float64]): The inertia tensor of the molecule
|
||||||
|
"""
|
||||||
|
|
||||||
|
molname: str
|
||||||
|
atom: List[Atom] = field(default_factory=list)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def total_mass(self) -> float:
|
||||||
|
return sum(atom.mass for atom in self.atom)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def com(self) -> npt.NDArray[np.float64]:
|
||||||
|
com = np.zeros(3)
|
||||||
|
|
||||||
|
for atom in self.atom:
|
||||||
|
com += atom.mass * np.array([atom.rx, atom.ry, atom.rz])
|
||||||
|
|
||||||
|
com = com / self.total_mass
|
||||||
|
|
||||||
|
return com
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def inertia_tensor(self) -> npt.NDArray[np.float64]:
|
||||||
|
"""
|
||||||
|
Calculates the inertia tensor of the molecule.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
npt.NDArray[np.float64]: inertia tensor of the molecule.
|
||||||
|
"""
|
||||||
|
inertia_tensor = np.zeros((3, 3), dtype=np.float64)
|
||||||
|
|
||||||
|
for atom in self.atom:
|
||||||
|
dx = atom.rx - self.com[0]
|
||||||
|
dy = atom.ry - self.com[1]
|
||||||
|
dz = atom.rz - self.com[2]
|
||||||
|
|
||||||
|
inertia_tensor[0, 0] += atom.mass * (dy**2 + dz**2)
|
||||||
|
inertia_tensor[1, 1] += atom.mass * (dz**2 + dx**2)
|
||||||
|
inertia_tensor[2, 2] += atom.mass * (dx**2 + dy**2)
|
||||||
|
|
||||||
|
inertia_tensor[0, 1] -= atom.mass * dx * dy
|
||||||
|
inertia_tensor[0, 2] -= atom.mass * dx * dz
|
||||||
|
inertia_tensor[1, 2] -= atom.mass * dy * dz
|
||||||
|
|
||||||
|
# enforce symmetry
|
||||||
|
inertia_tensor[1, 0] = inertia_tensor[0, 1]
|
||||||
|
inertia_tensor[2, 0] = inertia_tensor[0, 2]
|
||||||
|
inertia_tensor[2, 1] = inertia_tensor[1, 2]
|
||||||
|
|
||||||
|
return inertia_tensor
|
||||||
|
|
||||||
|
@invalidate_computed_properties()
|
||||||
|
def add_atom(self, a: Atom) -> None:
|
||||||
|
"""
|
||||||
|
Adds Atom instance to the molecule.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
a (Atom): Atom instance to be added to atom list.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.atom.append(a)
|
||||||
|
|
||||||
|
@invalidate_computed_properties()
|
||||||
|
def remove_atom(self, a: Atom) -> None:
|
||||||
|
"""
|
||||||
|
Removes Atom instance from the molecule.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
a (Atom): Atom instance to be removed from atom list.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.atom.remove(a)
|
||||||
|
|
||||||
|
@invalidate_computed_properties()
|
||||||
|
def move_center_of_mass_to_origin(self) -> None:
|
||||||
|
"""
|
||||||
|
Updated positions based on the center of mass of the molecule
|
||||||
|
"""
|
||||||
|
for atom in self.atom:
|
||||||
|
atom.rx -= self.com[0]
|
||||||
|
atom.ry -= self.com[1]
|
||||||
|
atom.rz -= self.com[2]
|
||||||
|
|
||||||
|
@invalidate_computed_properties()
|
||||||
|
def rotate_to_standard_orientation(self) -> None:
|
||||||
|
"""
|
||||||
|
Rotates the molecule to the standard orientation
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.move_center_of_mass_to_origin()
|
||||||
|
evals, evecs = self.principal_axes()
|
||||||
|
|
||||||
|
if np.isclose(linalg.det(evecs), -1):
|
||||||
|
evecs[:, 2] *= -1
|
||||||
|
|
||||||
|
if not np.isclose(linalg.det(evecs), 1):
|
||||||
|
raise RuntimeError(
|
||||||
|
"Error: could not make a rotation matrix while adopting the standard orientation"
|
||||||
|
)
|
||||||
|
|
||||||
|
coords = np.array([(a.rx, a.ry, a.rz) for a in self.atom])
|
||||||
|
rotated = coords @ evecs.T
|
||||||
|
|
||||||
|
for atom, pos in zip(self.atom, rotated):
|
||||||
|
atom.rx, atom.ry, atom.rz = pos
|
||||||
|
|
||||||
|
def charges_and_dipole(self) -> List[float]:
|
||||||
|
"""
|
||||||
|
Calculates the charges and dipole of the molecule atoms
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[float]: Respectivly magnitude of the: charge magnitude, first dipole,
|
||||||
|
second dipole, third dipole and total dipole.
|
||||||
|
"""
|
||||||
|
|
||||||
|
charge = 0
|
||||||
|
dipole = np.zeros(3)
|
||||||
|
for atom in self.atom:
|
||||||
|
position = np.array([atom.rx, atom.ry, atom.rz])
|
||||||
|
dipole += atom.chg * position
|
||||||
|
charge += atom.chg
|
||||||
|
|
||||||
|
dipole *= EA_2_DEBYE
|
||||||
|
total_dipole = math.sqrt(dipole[0] ** 2 + dipole[1] ** 2 + dipole[2] ** 2)
|
||||||
|
|
||||||
|
return [charge, dipole[0], dipole[1], dipole[2], total_dipole]
|
||||||
|
|
||||||
|
def distances_between_atoms(self) -> npt.NDArray[np.float64]:
|
||||||
|
"""
|
||||||
|
Calculates distances between the atoms of the molecule
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
NDArray[Shape["Any,Any"],Float]: distances between the atoms.
|
||||||
|
"""
|
||||||
|
coords = np.array([(a.rx, a.ry, a.rz) for a in self.atom], dtype=np.float64)
|
||||||
|
diff = coords[:, None, :] - coords[None, :, :]
|
||||||
|
return np.linalg.norm(diff, axis=-1)
|
||||||
|
|
||||||
|
def principal_axes(self) -> Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
|
||||||
|
"""
|
||||||
|
Calculates the principal axes of the molecule
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[np.ndarray, np.ndarray]: Tuple where the first value is the Eigen Values and the second is the Eigen Vectors,
|
||||||
|
representing the principal axes of the molecule.
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
evals, evecs = linalg.eigh(self.inertia_tensor)
|
||||||
|
|
||||||
|
idx = np.argsort(evals)
|
||||||
|
evals = evals[idx]
|
||||||
|
evecs = evecs[:, idx]
|
||||||
|
except ValueError:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Error: diagonalization of inertia tensor did not converge"
|
||||||
|
)
|
||||||
|
|
||||||
|
return evals, evecs
|
||||||
|
|
||||||
|
def read_position(self) -> npt.NDArray[np.float64]:
|
||||||
|
"""Reads the position of the molecule from the position values of the atoms
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
np.ndarray: internal position relative to atoms of the molecule
|
||||||
|
"""
|
||||||
|
coords = np.array([(a.rx, a.ry, a.rz) for a in self.atom], dtype=np.float64)
|
||||||
|
return coords.ravel() * BOHR2ANG
|
||||||
|
|
||||||
|
def update_charges(self, charges: npt.NDArray[np.float64]) -> int:
|
||||||
|
"""
|
||||||
|
Updates the charges of the atoms of the molecule and
|
||||||
|
returns the max difference between the new and old charges
|
||||||
|
"""
|
||||||
|
diff = 0
|
||||||
|
for i, atom in enumerate(self.atom):
|
||||||
|
diff = max(diff, abs(atom.chg - charges[i]))
|
||||||
|
atom.chg = charges[i]
|
||||||
|
|
||||||
|
return diff
|
||||||
|
|
||||||
|
def sizes_of_molecule(self) -> List[float]:
|
||||||
|
"""
|
||||||
|
Calculates sides of the smallest box that the molecule could fit
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[float]: list of the sizes of the molecule
|
||||||
|
"""
|
||||||
|
coords = np.array([(a.rx, a.ry, a.rz) for a in self.atom], dtype=np.float64)
|
||||||
|
return (coords.max(axis=0) - coords.min(axis=0)).tolist()
|
||||||
|
|
||||||
|
def translate(self, vector: np.ndarray) -> Self:
|
||||||
|
"""
|
||||||
|
Creates a new Molecule object where its' atoms has been translated by a vector
|
||||||
|
|
||||||
|
Args:
|
||||||
|
vector (np.ndarray): translation vector
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Molecule: new Molecule object translated by a vector
|
||||||
|
"""
|
||||||
|
vec = np.asarray(vector, dtype=np.float64)
|
||||||
|
if vec.shape != (3,):
|
||||||
|
raise ValueError("translation vector must be shape (3,)")
|
||||||
|
|
||||||
|
new_molecule = deepcopy(self)
|
||||||
|
|
||||||
|
for atom in new_molecule.atom:
|
||||||
|
atom.rx += vector[0]
|
||||||
|
atom.ry += vector[1]
|
||||||
|
atom.rz += vector[2]
|
||||||
|
|
||||||
|
return new_molecule
|
||||||
|
|
||||||
|
def print_mol_info(self) -> None:
|
||||||
|
"""
|
||||||
|
Prints the Molecule information into a Output File
|
||||||
|
"""
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
" Center of mass = ( {:>10.4f} , {:>10.4f} , {:>10.4f} )".format(
|
||||||
|
self.com[0], self.com[1], self.com[2]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
evals, evecs = self.principal_axes()
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
" Moments of inertia = {:>9E} {:>9E} {:>9E}".format(
|
||||||
|
evals[0], evals[1], evals[2]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
" Major principal axis = ( {:>10.6f} , {:>10.6f} , {:>10.6f} )".format(
|
||||||
|
evecs[0, 0], evecs[1, 0], evecs[2, 0]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
" Inter principal axis = ( {:>10.6f} , {:>10.6f} , {:>10.6f} )".format(
|
||||||
|
evecs[0, 1], evecs[1, 1], evecs[2, 1]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
" Minor principal axis = ( {:>10.6f} , {:>10.6f} , {:>10.6f} )".format(
|
||||||
|
evecs[0, 2], evecs[1, 2], evecs[2, 2]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
sizes = self.sizes_of_molecule()
|
||||||
|
logger.info(
|
||||||
|
" Characteristic lengths = ( {:>6.2f} , {:>6.2f} , {:>6.2f} )".format(
|
||||||
|
sizes[0], sizes[1], sizes[2]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
logger.info(" Total mass = {:>8.2f} au".format(self.total_mass))
|
||||||
|
|
||||||
|
chg_dip = self.charges_and_dipole()
|
||||||
|
logger.info(" Total charge = {:>8.4f} e".format(chg_dip[0]))
|
||||||
|
logger.info(
|
||||||
|
" Dipole moment = ( {:>9.4f} , {:>9.4f} , {:>9.4f} ) Total = {:>9.4f} Debye".format(
|
||||||
|
chg_dip[1], chg_dip[2], chg_dip[3], chg_dip[4]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def minimum_distance(self, molec: Self) -> float:
|
||||||
|
"""
|
||||||
|
Return the minimum distance between two molecules
|
||||||
|
|
||||||
|
Args:
|
||||||
|
molec (Molecule): Molecule object to be compared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
float: minimum distance between the two molecules
|
||||||
|
"""
|
||||||
|
coords_a = np.array(
|
||||||
|
[(a.rx, a.ry, a.rz) for a in self.atom if a.na != GHOST_NUMBER]
|
||||||
|
)
|
||||||
|
coords_b = np.array(
|
||||||
|
[(a.rx, a.ry, a.rz) for a in molec.atom if a.na != GHOST_NUMBER]
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(coords_a) == 0 or len(coords_b) == 0:
|
||||||
|
raise ValueError("No real atoms to compare")
|
||||||
|
|
||||||
|
diff = coords_a[:, None, :] - coords_b[None, :, :]
|
||||||
|
d2 = np.sum(diff**2, axis=-1)
|
||||||
|
return np.sqrt(d2.min())
|
||||||
30
diceplayer/environment/system.py
Normal file
30
diceplayer/environment/system.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
from diceplayer.environment.molecule import Molecule
|
||||||
|
|
||||||
|
from typing_extensions import List
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class System:
|
||||||
|
"""
|
||||||
|
System class declaration. This class is used throughout the DicePlayer program to represent the system containing the molecules.
|
||||||
|
|
||||||
|
Atributes:
|
||||||
|
molecule (List[Molecule]): List of molecules of the system
|
||||||
|
nmols (List[int]): List of number of molecules in the system
|
||||||
|
"""
|
||||||
|
|
||||||
|
nmols: List[int] = field(default_factory=list)
|
||||||
|
molecule: List[Molecule] = field(default_factory=list)
|
||||||
|
|
||||||
|
def add_type(self, m: Molecule) -> None:
|
||||||
|
"""
|
||||||
|
Adds a new molecule type to the system
|
||||||
|
|
||||||
|
Args:
|
||||||
|
m (Molecule): The instance of the new type of molecule
|
||||||
|
"""
|
||||||
|
if not isinstance(m, Molecule):
|
||||||
|
raise TypeError("Error: molecule is not a Molecule instance")
|
||||||
|
self.molecule.append(m)
|
||||||
4
diceplayer/logger.py
Normal file
4
diceplayer/logger.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from diceplayer.utils import RunLogger
|
||||||
|
|
||||||
|
|
||||||
|
logger = RunLogger("diceplayer")
|
||||||
19
diceplayer/optimization/optimization_handler.py
Normal file
19
diceplayer/optimization/optimization_handler.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from diceplayer.config.player_config import RoutineType
|
||||||
|
from diceplayer.state.state_model import StateModel
|
||||||
|
|
||||||
|
|
||||||
|
class OptimizationHandler:
|
||||||
|
@staticmethod
|
||||||
|
def run(state: StateModel, current_cycle: int) -> StateModel:
|
||||||
|
print(f"Running Optimization - {current_cycle}")
|
||||||
|
return state
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _fetch_current_routine(state: StateModel, current_cycle: int) -> RoutineType:
|
||||||
|
if state.config.type != RoutineType.BOTH:
|
||||||
|
return state.config.type
|
||||||
|
|
||||||
|
if current_cycle < state.config.switch_cyc:
|
||||||
|
return RoutineType.CHARGE
|
||||||
|
|
||||||
|
return RoutineType.GEOMETRY
|
||||||
@@ -1,448 +1,55 @@
|
|||||||
from diceplayer import VERSION, logger
|
from diceplayer.config.player_config import PlayerConfig
|
||||||
from diceplayer.shared.config.dice_config import DiceConfig
|
from diceplayer.dice.dice_handler import DiceHandler
|
||||||
from diceplayer.shared.config.gaussian_config import GaussianDTO
|
from diceplayer.logger import logger
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
from diceplayer.state.state_handler import StateHandler
|
||||||
from diceplayer.shared.environment.atom import Atom
|
from diceplayer.state.state_model import StateModel
|
||||||
from diceplayer.shared.environment.molecule import Molecule
|
from diceplayer.utils.potential import read_system_from_phb
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
from diceplayer.shared.interface.dice_interface import DiceInterface
|
|
||||||
from diceplayer.shared.interface.gaussian_interface import GaussianInterface
|
|
||||||
from diceplayer.shared.utils.dataclass_protocol import Dataclass
|
|
||||||
from diceplayer.shared.utils.misc import weekday_date_time
|
|
||||||
from diceplayer.shared.utils.ptable import atomsymb
|
|
||||||
|
|
||||||
import yaml
|
from typing_extensions import TypedDict, Unpack
|
||||||
|
|
||||||
import os
|
|
||||||
import pickle
|
|
||||||
import sys
|
|
||||||
from dataclasses import fields
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Tuple, Type
|
|
||||||
|
|
||||||
ENV = ["OMP_STACKSIZE"]
|
class PlayerFlags(TypedDict):
|
||||||
|
continuation: bool
|
||||||
|
force: bool
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, infile: str = None, optimization: bool = False):
|
def __init__(self, config: PlayerConfig):
|
||||||
if infile is None and optimization is False:
|
self.config = config
|
||||||
raise ValueError("Must specify either infile or optimization")
|
self._state_handler = StateHandler(config.simulation_dir)
|
||||||
|
|
||||||
elif infile is not None:
|
def play(self, **flags: Unpack[PlayerFlags]):
|
||||||
self.config = self.set_config(self.read_keywords(infile))
|
continuation = flags.get("continuation", False)
|
||||||
|
force = flags.get("force", False)
|
||||||
|
|
||||||
self.system = System()
|
state = self._state_handler.get(self.config, force=force)
|
||||||
|
if not continuation and state is not None:
|
||||||
self.initial_cycle = 1
|
logger.info(
|
||||||
|
"Continuation flag is not set. Starting a new simulation and deleting any existing state."
|
||||||
elif optimization is True:
|
)
|
||||||
save = self.load_run_from_pickle()
|
self._state_handler.delete()
|
||||||
|
state = None
|
||||||
self.config = save[0]
|
|
||||||
|
|
||||||
self.system = save[1]
|
|
||||||
|
|
||||||
self.initial_cycle = save[2] + 1
|
|
||||||
|
|
||||||
|
if state is None:
|
||||||
|
system = read_system_from_phb(self.config)
|
||||||
|
state = StateModel(config=self.config, system=system)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Must specify either infile or config")
|
logger.info("Resuming from existing state.")
|
||||||
|
|
||||||
self.dice_interface = DiceInterface()
|
while state.current_cycle < self.config.max_cyc:
|
||||||
self.gaussian_interface = GaussianInterface()
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
logger.info(
|
|
||||||
"==========================================================================================\n"
|
|
||||||
"Starting the iterative process.\n"
|
|
||||||
"==========================================================================================\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
for cycle in range(self.initial_cycle, self.initial_cycle + self.config.maxcyc):
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"------------------------------------------------------------------------------------------\n"
|
f"Starting cycle {state.current_cycle + 1} of {self.config.max_cyc}."
|
||||||
f" Step # {cycle}\n"
|
|
||||||
f"------------------------------------------------------------------------------------------\n"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.dice_start(cycle)
|
step_directory = self.config.simulation_dir / f"{state.current_cycle:02d}"
|
||||||
|
if not step_directory.exists():
|
||||||
|
step_directory.mkdir(parents=True)
|
||||||
|
|
||||||
try:
|
state = DiceHandler(step_directory).run(state, state.current_cycle)
|
||||||
self.gaussian_start(cycle)
|
|
||||||
except StopIteration:
|
|
||||||
break
|
|
||||||
|
|
||||||
self.save_run_in_pickle(cycle)
|
# state = OptimizationHandler.run(state, state.current_cycle)
|
||||||
|
|
||||||
def prepare_system(self):
|
state.current_cycle += 1
|
||||||
for i, mol in enumerate(self.system.molecule):
|
self._state_handler.save(state)
|
||||||
logger.info(f"Molecule {i + 1} - {mol.molname}")
|
|
||||||
|
|
||||||
mol.print_mol_info()
|
logger.info("Reached maximum number of cycles. Simulation complete.")
|
||||||
logger.info(
|
|
||||||
"\n Translating and rotating molecule to standard orientation..."
|
|
||||||
)
|
|
||||||
|
|
||||||
mol.standard_orientation()
|
|
||||||
logger.info("\n Done")
|
|
||||||
logger.info("\nNew values:\n")
|
|
||||||
mol.print_mol_info()
|
|
||||||
|
|
||||||
logger.info("\n")
|
|
||||||
|
|
||||||
def create_simulation_dir(self):
|
|
||||||
simulation_dir_path = Path(self.config.simulation_dir)
|
|
||||||
if simulation_dir_path.exists():
|
|
||||||
raise FileExistsError(
|
|
||||||
f"Error: a file or a directory {self.config.simulation_dir} already exists,"
|
|
||||||
f" move or delete the simfiles directory to continue."
|
|
||||||
)
|
|
||||||
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 log_keywords(config: Dataclass, dto: Type[Dataclass]):
|
|
||||||
for key in sorted(list(map(lambda f: f.name, fields(dto)))):
|
|
||||||
if getattr(config, key) is not None:
|
|
||||||
if isinstance(getattr(config, key), list):
|
|
||||||
string = " ".join(str(x) for x in getattr(config, key))
|
|
||||||
logger.info(f"{key} = [ {string} ]")
|
|
||||||
else:
|
|
||||||
logger.info(f"{key} = {getattr(config, key)}")
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
f"##########################################################################################\n"
|
|
||||||
f"############# Welcome to DICEPLAYER version {VERSION} #############\n"
|
|
||||||
f"##########################################################################################\n"
|
|
||||||
)
|
|
||||||
logger.info("Your python version is {}\n".format(sys.version))
|
|
||||||
logger.info("Program started on {}\n".format(weekday_date_time()))
|
|
||||||
logger.info("Environment variables:")
|
|
||||||
for var in ENV:
|
|
||||||
logger.info(
|
|
||||||
"{} = {}\n".format(
|
|
||||||
var, (os.environ[var] if var in os.environ else "Not set")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
"------------------------------------------------------------------------------------------\n"
|
|
||||||
" DICE variables being used in this run:\n"
|
|
||||||
"------------------------------------------------------------------------------------------\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
log_keywords(self.config.dice, DiceConfig)
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
"------------------------------------------------------------------------------------------\n"
|
|
||||||
" GAUSSIAN variables being used in this run:\n"
|
|
||||||
"------------------------------------------------------------------------------------------\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
log_keywords(self.config.gaussian, GaussianDTO)
|
|
||||||
|
|
||||||
logger.info("\n")
|
|
||||||
|
|
||||||
def read_potentials(self):
|
|
||||||
ljname_path = Path(self.config.dice.ljname)
|
|
||||||
if ljname_path.exists():
|
|
||||||
with open(self.config.dice.ljname) as file:
|
|
||||||
ljc_data = file.readlines()
|
|
||||||
else:
|
|
||||||
raise RuntimeError(f"Potential file {self.config.dice.ljname} not found.")
|
|
||||||
|
|
||||||
combrule = ljc_data.pop(0).split()[0]
|
|
||||||
if combrule not in ("*", "+"):
|
|
||||||
sys.exit(
|
|
||||||
"Error: expected a '*' or a '+' sign in 1st line of file {}".format(
|
|
||||||
self.config.dice.ljname
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.config.dice.combrule = combrule
|
|
||||||
|
|
||||||
ntypes = ljc_data.pop(0).split()[0]
|
|
||||||
if not ntypes.isdigit():
|
|
||||||
sys.exit(
|
|
||||||
"Error: expected an integer in the 2nd line of file {}".format(
|
|
||||||
self.config.dice.ljname
|
|
||||||
)
|
|
||||||
)
|
|
||||||
ntypes = int(ntypes)
|
|
||||||
|
|
||||||
if ntypes != len(self.config.dice.nmol):
|
|
||||||
sys.exit(
|
|
||||||
f"Error: number of molecule types in file {self.config.dice.ljname} "
|
|
||||||
f"must match that of 'nmol' keyword in config file"
|
|
||||||
)
|
|
||||||
|
|
||||||
for i in range(ntypes):
|
|
||||||
try:
|
|
||||||
nsites, molname = ljc_data.pop(0).split()[:2]
|
|
||||||
except ValueError:
|
|
||||||
raise ValueError(
|
|
||||||
f"Error: expected nsites and molname for the molecule type {i + 1}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not nsites.isdigit():
|
|
||||||
raise ValueError(
|
|
||||||
f"Error: expected nsites to be an integer for molecule type {i + 1}"
|
|
||||||
)
|
|
||||||
|
|
||||||
nsites = int(nsites)
|
|
||||||
self.system.add_type(Molecule(molname))
|
|
||||||
|
|
||||||
atom_fields = ["lbl", "na", "rx", "ry", "rz", "chg", "eps", "sig"]
|
|
||||||
for j in range(nsites):
|
|
||||||
new_atom = dict(zip(atom_fields, ljc_data.pop(0).split()))
|
|
||||||
self.system.molecule[i].add_atom(
|
|
||||||
Atom(**self.validate_atom_dict(i, j, new_atom))
|
|
||||||
)
|
|
||||||
|
|
||||||
def print_potentials(self) -> None:
|
|
||||||
formatstr = "{:<3d} {:>3d} {:>10.5f} {:>10.5f} {:>10.5f} {:>10.6f} {:>9.5f} {:>7.4f} {:>9.4f}"
|
|
||||||
logger.info(
|
|
||||||
"==========================================================================================\n"
|
|
||||||
f" Potential parameters from file {self.config.dice.ljname}:\n"
|
|
||||||
"------------------------------------------------------------------------------------------"
|
|
||||||
"\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(f"Combination rule: {self.config.dice.combrule}")
|
|
||||||
logger.info(f"Types of molecules: {len(self.system.molecule)}\n")
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
for mol in self.system.molecule:
|
|
||||||
i += 1
|
|
||||||
logger.info("{} atoms in molecule type {}:".format(len(mol.atom), i))
|
|
||||||
logger.info(
|
|
||||||
"---------------------------------------------------------------------------------"
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
"Lbl AN X Y Z Charge Epsilon Sigma Mass"
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
"---------------------------------------------------------------------------------"
|
|
||||||
)
|
|
||||||
|
|
||||||
for atom in mol.atom:
|
|
||||||
logger.info(
|
|
||||||
formatstr.format(
|
|
||||||
atom.lbl,
|
|
||||||
atom.na,
|
|
||||||
atom.rx,
|
|
||||||
atom.ry,
|
|
||||||
atom.rz,
|
|
||||||
atom.chg,
|
|
||||||
atom.eps,
|
|
||||||
atom.sig,
|
|
||||||
atom.mass,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("\n")
|
|
||||||
|
|
||||||
def dice_start(self, cycle: int):
|
|
||||||
self.dice_interface.configure(
|
|
||||||
self.config,
|
|
||||||
self.system,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.dice_interface.start(cycle)
|
|
||||||
|
|
||||||
self.dice_interface.reset()
|
|
||||||
|
|
||||||
def gaussian_start(self, cycle: int):
|
|
||||||
self.gaussian_interface.configure(
|
|
||||||
self.config,
|
|
||||||
self.system,
|
|
||||||
)
|
|
||||||
|
|
||||||
result = self.gaussian_interface.start(cycle)
|
|
||||||
|
|
||||||
self.gaussian_interface.reset()
|
|
||||||
|
|
||||||
if self.config.opt:
|
|
||||||
if "position" not in result:
|
|
||||||
raise RuntimeError("Optimization failed. No position found in result.")
|
|
||||||
|
|
||||||
self.system.update_molecule(result["position"])
|
|
||||||
|
|
||||||
else:
|
|
||||||
if "charges" not in result:
|
|
||||||
raise RuntimeError(
|
|
||||||
"Charges optimization failed. No charges found in result."
|
|
||||||
)
|
|
||||||
|
|
||||||
diff = self.system.molecule[0].update_charges(result["charges"])
|
|
||||||
|
|
||||||
self.system.print_charges_and_dipole(cycle)
|
|
||||||
self.print_geoms(cycle)
|
|
||||||
|
|
||||||
if diff < self.config.gaussian.chg_tol:
|
|
||||||
logger.info(f"Charges converged after {cycle} cycles.")
|
|
||||||
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
|
|
||||||
def validate_atom_dict(molecule_type, molecule_site, atom_dict: dict) -> dict:
|
|
||||||
molecule_type += 1
|
|
||||||
molecule_site += 1
|
|
||||||
|
|
||||||
if len(atom_dict) < 8:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid number of fields for site {molecule_site} for molecule type {molecule_type}."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["lbl"] = int(atom_dict["lbl"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid lbl fields for site {molecule_site} for molecule type {molecule_type}."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["na"] = int(atom_dict["na"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid na fields for site {molecule_site} for molecule type {molecule_type}."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["rx"] = float(atom_dict["rx"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid rx fields for site {molecule_site} for molecule type {molecule_type}. "
|
|
||||||
f"Value must be a float."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["ry"] = float(atom_dict["ry"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid ry fields for site {molecule_site} for molecule type {molecule_type}. "
|
|
||||||
f"Value must be a float."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["rz"] = float(atom_dict["rz"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid rz fields for site {molecule_site} for molecule type {molecule_type}. "
|
|
||||||
f"Value must be a float."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["chg"] = float(atom_dict["chg"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid chg fields for site {molecule_site} for molecule type {molecule_type}. "
|
|
||||||
f"Value must be a float."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["eps"] = float(atom_dict["eps"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid eps fields for site {molecule_site} for molecule type {molecule_type}. "
|
|
||||||
f"Value must be a float."
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
atom_dict["sig"] = float(atom_dict["sig"])
|
|
||||||
except Exception:
|
|
||||||
raise ValueError(
|
|
||||||
f"Invalid sig fields for site {molecule_site} for molecule type {molecule_type}. "
|
|
||||||
f"Value must be a float."
|
|
||||||
)
|
|
||||||
|
|
||||||
return atom_dict
|
|
||||||
|
|
||||||
def print_results(self):
|
|
||||||
formatstr = "{:<3d} {:>3d} {:>10.5f} {:>10.5f} {:>10.5f} {:>10.6f} {:>9.5f} {:>7.4f} {:>9.4f}"
|
|
||||||
|
|
||||||
mol = self.system.molecule[0]
|
|
||||||
logger.info("{} atoms in molecule type {}:".format(len(mol.atom), 1))
|
|
||||||
logger.info(
|
|
||||||
"---------------------------------------------------------------------------------"
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
"Lbl AN X Y Z Charge Epsilon Sigma Mass"
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
"---------------------------------------------------------------------------------"
|
|
||||||
)
|
|
||||||
|
|
||||||
for atom in mol.atom:
|
|
||||||
logger.info(
|
|
||||||
formatstr.format(
|
|
||||||
atom.lbl,
|
|
||||||
atom.na,
|
|
||||||
atom.rx,
|
|
||||||
atom.ry,
|
|
||||||
atom.rz,
|
|
||||||
atom.chg,
|
|
||||||
atom.eps,
|
|
||||||
atom.sig,
|
|
||||||
atom.mass,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("\n")
|
|
||||||
|
|
||||||
def save_run_in_pickle(self, cycle):
|
|
||||||
try:
|
|
||||||
with open("latest-step.pkl", "wb") as pickle_file:
|
|
||||||
pickle.dump((self.config, self.system, cycle), pickle_file)
|
|
||||||
except Exception:
|
|
||||||
raise RuntimeError(f"Could not save pickle file latest-step.pkl.")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def load_run_from_pickle() -> Tuple[PlayerConfig, System, int]:
|
|
||||||
pickle_path = Path("latest-step.pkl")
|
|
||||||
try:
|
|
||||||
with open(pickle_path, "rb") as pickle_file:
|
|
||||||
save = pickle.load(pickle_file)
|
|
||||||
return save[0], save[1], save[2] + 1
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
raise RuntimeError(f"Could not load pickle file {pickle_path}.")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def set_config(data: dict) -> PlayerConfig:
|
|
||||||
return PlayerConfig.from_dict(data)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def read_keywords(infile) -> dict:
|
|
||||||
with open(infile, "r") as yml_file:
|
|
||||||
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
|
|
||||||
def from_file(cls, infile: str) -> "Player":
|
|
||||||
return cls(infile=infile)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_save(cls):
|
|
||||||
return cls(optimization=True)
|
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
from diceplayer.shared.utils.dataclass_protocol import Dataclass
|
|
||||||
|
|
||||||
from dataclasses import dataclass, fields
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DiceConfig(Dataclass):
|
|
||||||
"""
|
|
||||||
Data Transfer Object for the Dice configuration.
|
|
||||||
"""
|
|
||||||
|
|
||||||
ljname: str
|
|
||||||
outname: str
|
|
||||||
dens: float
|
|
||||||
nmol: List[int]
|
|
||||||
nstep: List[int]
|
|
||||||
|
|
||||||
upbuf = 360
|
|
||||||
combrule = "*"
|
|
||||||
isave: int = 1000
|
|
||||||
press: float = 1.0
|
|
||||||
temp: float = 300.0
|
|
||||||
progname: str = "dice"
|
|
||||||
randominit: str = "first"
|
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
if not isinstance(self.ljname, str):
|
|
||||||
raise ValueError("Error: 'ljname' keyword not specified in config file")
|
|
||||||
|
|
||||||
if not isinstance(self.outname, str):
|
|
||||||
raise ValueError("Error: 'outname' keyword not specified in config file")
|
|
||||||
|
|
||||||
if not isinstance(self.dens, float):
|
|
||||||
raise ValueError("Error: 'dens' keyword not specified in config file")
|
|
||||||
|
|
||||||
if not isinstance(self.nmol, list):
|
|
||||||
raise ValueError(
|
|
||||||
"Error: 'nmol' keyword not defined appropriately in config file"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not isinstance(self.nstep, list) or len(self.nstep) not in (2, 3):
|
|
||||||
raise ValueError(
|
|
||||||
"Error: 'nstep' keyword not defined appropriately in config file"
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, params: dict):
|
|
||||||
params = {f.name: params[f.name] for f in fields(cls) if f.name in params}
|
|
||||||
|
|
||||||
return cls(**params)
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
from diceplayer.shared.utils.dataclass_protocol import Dataclass
|
|
||||||
|
|
||||||
from dataclasses import dataclass, fields
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class GaussianDTO(Dataclass):
|
|
||||||
"""
|
|
||||||
Data Transfer Object for the Gaussian configuration.
|
|
||||||
"""
|
|
||||||
|
|
||||||
level: str
|
|
||||||
qmprog: str
|
|
||||||
|
|
||||||
chgmult = [0, 1]
|
|
||||||
pop: str = "chelpg"
|
|
||||||
chg_tol: float = 0.01
|
|
||||||
keywords: str = None
|
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
if self.qmprog not in ("g03", "g09", "g16"):
|
|
||||||
raise ValueError("Error: invalid qmprog value.")
|
|
||||||
if self.level is None:
|
|
||||||
raise ValueError("Error: 'level' keyword not specified in config file.")
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, params: dict):
|
|
||||||
params = {f.name: params[f.name] for f in fields(cls) if f.name in params}
|
|
||||||
|
|
||||||
return cls(**params)
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
from diceplayer.shared.config.dice_config import DiceConfig
|
|
||||||
from diceplayer.shared.config.gaussian_config import GaussianDTO
|
|
||||||
from diceplayer.shared.utils.dataclass_protocol import Dataclass
|
|
||||||
|
|
||||||
from dataclasses import dataclass, fields
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class PlayerConfig(Dataclass):
|
|
||||||
"""
|
|
||||||
Data Transfer Object for the player configuration.
|
|
||||||
"""
|
|
||||||
|
|
||||||
opt: bool
|
|
||||||
maxcyc: int
|
|
||||||
nprocs: int
|
|
||||||
ncores: int
|
|
||||||
|
|
||||||
dice: DiceConfig
|
|
||||||
gaussian: GaussianDTO
|
|
||||||
|
|
||||||
mem: int = None
|
|
||||||
switchcyc: int = 3
|
|
||||||
qmprog: str = "g16"
|
|
||||||
altsteps: int = 20000
|
|
||||||
geoms_file = "geoms.xyz"
|
|
||||||
simulation_dir = "simfiles"
|
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
MIN_STEP = 20000
|
|
||||||
# altsteps value is always the nearest multiple of 1000
|
|
||||||
self.altsteps = round(max(MIN_STEP, self.altsteps) / 1000) * 1000
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, params: dict):
|
|
||||||
if params["dice"] is None:
|
|
||||||
raise ValueError("Error: 'dice' keyword not specified in config file.")
|
|
||||||
params["dice"] = DiceConfig.from_dict(params["dice"])
|
|
||||||
|
|
||||||
if params["gaussian"] is None:
|
|
||||||
raise ValueError("Error: 'gaussian' keyword not specified in config file.")
|
|
||||||
params["gaussian"] = GaussianDTO.from_dict(params["gaussian"])
|
|
||||||
|
|
||||||
params = {f.name: params[f.name] for f in fields(cls) if f.name in params}
|
|
||||||
|
|
||||||
return cls(**params)
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
from diceplayer.shared.utils.ptable import atommass
|
|
||||||
|
|
||||||
|
|
||||||
class Atom:
|
|
||||||
"""
|
|
||||||
Atom class declaration. This class is used throughout the DicePlayer program to represent atoms.
|
|
||||||
|
|
||||||
Atributes:
|
|
||||||
lbl (int): Dice derived variable used to represent atoms with identical energies and simetric positions.
|
|
||||||
na (int): Atomic number of the represented atom.
|
|
||||||
rx (float): x cartesian coordinates of the represented atom.
|
|
||||||
ry (float): y cartesian coordinates of the represented atom.
|
|
||||||
rz (float): z cartesian coordinates of the represented atom.
|
|
||||||
chg (float): charge of the represented atom.
|
|
||||||
eps (float): quantum number epsilon of the represented atom.
|
|
||||||
sig (float): quantum number sigma of the represented atom.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
lbl: int,
|
|
||||||
na: int,
|
|
||||||
rx: float,
|
|
||||||
ry: float,
|
|
||||||
rz: float,
|
|
||||||
chg: float,
|
|
||||||
eps: float,
|
|
||||||
sig: float,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
The constructor function __init__ is used to create new instances of the Atom class.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
lbl (int): Dice derived variable used to represent atoms with identical energies and simetric positions.
|
|
||||||
na (int): Atomic number of the represented atom.
|
|
||||||
rx (float): x cartesian coordinates of the represented atom.
|
|
||||||
ry (float): y cartesian coordinates of the represented atom.
|
|
||||||
rz (float): z cartesian coordinates of the represented atom.
|
|
||||||
chg (float): charge of the represented atom.
|
|
||||||
eps (float): quantum number epsilon of the represented atom.
|
|
||||||
sig (float): quantum number sigma of the represented atom.
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.lbl = lbl
|
|
||||||
self.na = na
|
|
||||||
self.rx = rx
|
|
||||||
self.ry = ry
|
|
||||||
self.rz = rz
|
|
||||||
self.chg = chg
|
|
||||||
self.eps = eps
|
|
||||||
self.sig = sig
|
|
||||||
self.mass = atommass[self.na]
|
|
||||||
@@ -1,384 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from nptyping import Float, NDArray, Shape
|
|
||||||
|
|
||||||
from diceplayer import logger
|
|
||||||
from diceplayer.shared.environment.atom import Atom
|
|
||||||
from diceplayer.shared.utils.misc import BOHR2ANG
|
|
||||||
from diceplayer.shared.utils.ptable import ghost_number
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from numpy.linalg import linalg
|
|
||||||
|
|
||||||
import math
|
|
||||||
from copy import deepcopy
|
|
||||||
from typing import Any, List, Tuple, Union
|
|
||||||
|
|
||||||
|
|
||||||
class Molecule:
|
|
||||||
"""
|
|
||||||
Molecule class declaration. This class is used throughout the DicePlayer program to represent molecules.
|
|
||||||
|
|
||||||
Atributes:
|
|
||||||
molname (str): The name of the represented molecule
|
|
||||||
atom (List[Atom]): List of atoms of the represented molecule
|
|
||||||
position (NDArray[Any, Any]): The position relative to the internal atoms of the represented molecule
|
|
||||||
energy (NDArray[Any, Any]): The energy of the represented molecule
|
|
||||||
gradient (NDArray[Any, Any]): The first derivative of the energy relative to the position
|
|
||||||
hessian (NDArray[Any, Any]): The second derivative of the energy relative to the position
|
|
||||||
total_mass (int): The total mass of the molecule
|
|
||||||
com (NDArray[Any, Any]): The center of mass of the molecule
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, molname: str) -> None:
|
|
||||||
"""
|
|
||||||
The constructor function __init__ is used to create new instances of the Molecule class.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
molname (str): Molecule name
|
|
||||||
"""
|
|
||||||
self.molname: str = molname
|
|
||||||
|
|
||||||
self.atom: List[Atom] = []
|
|
||||||
self.position: NDArray[Any, Any]
|
|
||||||
self.energy: NDArray[Any, Any]
|
|
||||||
self.gradient: NDArray[Any, Any]
|
|
||||||
self.hessian: NDArray[Any, Any]
|
|
||||||
|
|
||||||
self.ghost_atoms: List[Atom] = []
|
|
||||||
self.lp_atoms: List[Atom] = []
|
|
||||||
|
|
||||||
self.total_mass: int = 0
|
|
||||||
self.com: Union[None, NDArray[Any, Any]] = None
|
|
||||||
|
|
||||||
def add_atom(self, a: Atom) -> None:
|
|
||||||
"""
|
|
||||||
Adds Atom instance to the molecule.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
a (Atom): Atom instance to be added to atom list.
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.atom.append(a)
|
|
||||||
self.total_mass += a.mass
|
|
||||||
|
|
||||||
self.center_of_mass()
|
|
||||||
|
|
||||||
def center_of_mass(self) -> NDArray[Any, Any]:
|
|
||||||
"""
|
|
||||||
Calculates the center of mass of the molecule
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.com = np.zeros(3)
|
|
||||||
|
|
||||||
for atom in self.atom:
|
|
||||||
self.com += atom.mass * np.array([atom.rx, atom.ry, atom.rz])
|
|
||||||
|
|
||||||
self.com = self.com / self.total_mass
|
|
||||||
|
|
||||||
return self.com
|
|
||||||
|
|
||||||
def center_of_mass_to_origin(self) -> None:
|
|
||||||
"""
|
|
||||||
Updated positions based on the center of mass of the molecule
|
|
||||||
"""
|
|
||||||
for atom in self.atom:
|
|
||||||
atom.rx -= self.com[0]
|
|
||||||
atom.ry -= self.com[1]
|
|
||||||
atom.rz -= self.com[2]
|
|
||||||
|
|
||||||
self.center_of_mass()
|
|
||||||
|
|
||||||
def charges_and_dipole(self) -> List[float]:
|
|
||||||
"""
|
|
||||||
Calculates the charges and dipole of the molecule atoms
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List[float]: Respectivly magnitude of the: charge magnitude, first dipole,
|
|
||||||
second dipole, third dipole and total dipole.
|
|
||||||
"""
|
|
||||||
|
|
||||||
eA_to_Debye = 1 / 0.20819434
|
|
||||||
charge = 0
|
|
||||||
dipole = np.zeros(3)
|
|
||||||
for atom in self.atom:
|
|
||||||
position = np.array([atom.rx, atom.ry, atom.rz])
|
|
||||||
dipole += atom.chg * position
|
|
||||||
charge += atom.chg
|
|
||||||
|
|
||||||
dipole *= eA_to_Debye
|
|
||||||
total_dipole = math.sqrt(dipole[0] ** 2 + dipole[1] ** 2 + dipole[2] ** 2)
|
|
||||||
|
|
||||||
return [charge, dipole[0], dipole[1], dipole[2], total_dipole]
|
|
||||||
|
|
||||||
def distances_between_atoms(self) -> NDArray[Shape["Any,Any"], Float]:
|
|
||||||
"""
|
|
||||||
Calculates distances between the atoms of the molecule
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
NDArray[Shape["Any,Any"],Float]: distances between the atoms.
|
|
||||||
"""
|
|
||||||
|
|
||||||
distances = []
|
|
||||||
dim = len(self.atom)
|
|
||||||
for index1, atom1 in enumerate(self.atom):
|
|
||||||
for index2, atom2 in enumerate(self.atom):
|
|
||||||
if index1 != index2:
|
|
||||||
dx = atom1.rx - atom2.rx
|
|
||||||
dy = atom1.ry - atom2.ry
|
|
||||||
dz = atom1.rz - atom2.rz
|
|
||||||
distances.append(math.sqrt(dx**2 + dy**2 + dz**2))
|
|
||||||
|
|
||||||
return np.array(distances).reshape(dim, dim - 1)
|
|
||||||
|
|
||||||
def inertia_tensor(self) -> NDArray[Shape["3, 3"], Float]:
|
|
||||||
"""
|
|
||||||
Calculates the inertia tensor of the molecule.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
NDArray[Shape["3, 3"], Float]: inertia tensor of the molecule.
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.center_of_mass()
|
|
||||||
Ixx = Ixy = Ixz = Iyy = Iyz = Izz = 0.0
|
|
||||||
|
|
||||||
for atom in self.atom:
|
|
||||||
dx = atom.rx - self.com[0]
|
|
||||||
dy = atom.ry - self.com[1]
|
|
||||||
dz = atom.rz - self.com[2]
|
|
||||||
|
|
||||||
Ixx += atom.mass * (dy**2 + dz**2)
|
|
||||||
Iyy += atom.mass * (dz**2 + dx**2)
|
|
||||||
Izz += atom.mass * (dx**2 + dy**2)
|
|
||||||
|
|
||||||
Ixy += atom.mass * dx * dy * -1
|
|
||||||
Ixz += atom.mass * dx * dz * -1
|
|
||||||
Iyz += atom.mass * dy * dz * -1
|
|
||||||
|
|
||||||
return np.array([[Ixx, Ixy, Ixz], [Ixy, Iyy, Iyz], [Ixz, Iyz, Izz]])
|
|
||||||
|
|
||||||
def principal_axes(self) -> Tuple[np.ndarray, np.ndarray]:
|
|
||||||
"""
|
|
||||||
Calculates the principal axes of the molecule
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Tuple[np.ndarray, np.ndarray]: Tuple where the first value is the Eigen Values and the second is the Eigen Vectors,
|
|
||||||
representing the principal axes of the molecule.
|
|
||||||
"""
|
|
||||||
|
|
||||||
try:
|
|
||||||
evals, evecs = linalg.eigh(self.inertia_tensor())
|
|
||||||
except ValueError:
|
|
||||||
raise RuntimeError(
|
|
||||||
"Error: diagonalization of inertia tensor did not converge"
|
|
||||||
)
|
|
||||||
|
|
||||||
return evals, evecs
|
|
||||||
|
|
||||||
def read_position(self) -> np.ndarray:
|
|
||||||
"""Reads the position of the molecule from the position values of the atoms
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
np.ndarray: internal position relative to atoms of the molecule
|
|
||||||
"""
|
|
||||||
|
|
||||||
position_list = []
|
|
||||||
for atom in self.atom:
|
|
||||||
position_list.extend([atom.rx, atom.ry, atom.rz])
|
|
||||||
position = np.array(position_list)
|
|
||||||
position *= BOHR2ANG
|
|
||||||
|
|
||||||
return position
|
|
||||||
|
|
||||||
def update_charges(self, charges: NDArray) -> int:
|
|
||||||
"""
|
|
||||||
Updates the charges of the atoms of the molecule and
|
|
||||||
returns the max difference between the new and old charges
|
|
||||||
"""
|
|
||||||
diff = 0
|
|
||||||
for i, atom in enumerate(self.atom):
|
|
||||||
diff = max(diff, abs(atom.chg - charges[i]))
|
|
||||||
atom.chg = charges[i]
|
|
||||||
|
|
||||||
return diff
|
|
||||||
|
|
||||||
# @staticmethod
|
|
||||||
# def update_hessian(
|
|
||||||
# step: np.ndarray,
|
|
||||||
# cur_gradient: np.ndarray,
|
|
||||||
# old_gradient: np.ndarray,
|
|
||||||
# hessian: np.ndarray,
|
|
||||||
# ) -> np.ndarray:
|
|
||||||
# """
|
|
||||||
# Updates the Hessian of the molecule based on the current hessian, the current gradient and the previous gradient
|
|
||||||
#
|
|
||||||
# Args:
|
|
||||||
# step (np.ndarray): step value of the iteration
|
|
||||||
# cur_gradient (np.ndarray): current gradient
|
|
||||||
# old_gradient (np.ndarray): previous gradient
|
|
||||||
# hessian (np.ndarray): current hessian
|
|
||||||
#
|
|
||||||
# Returns:
|
|
||||||
# np.ndarray: updated hessian of the molecule
|
|
||||||
# """
|
|
||||||
#
|
|
||||||
# dif_gradient = cur_gradient - old_gradient
|
|
||||||
#
|
|
||||||
# mat1 = 1 / np.dot(dif_gradient, step) * np.matmul(dif_gradient.T, dif_gradient)
|
|
||||||
# mat2 = 1 / np.dot(step, np.matmul(hessian, step.T).T)
|
|
||||||
# mat2 *= np.matmul(np.matmul(hessian, step.T), np.matmul(step, hessian))
|
|
||||||
#
|
|
||||||
# return hessian + mat1 - mat2
|
|
||||||
|
|
||||||
def sizes_of_molecule(self) -> List[float]:
|
|
||||||
"""
|
|
||||||
Calculates sides of the smallest box that the molecule could fit
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List[float]: list of the sizes of the molecule
|
|
||||||
"""
|
|
||||||
|
|
||||||
x_list = []
|
|
||||||
y_list = []
|
|
||||||
z_list = []
|
|
||||||
|
|
||||||
for atom in self.atom:
|
|
||||||
x_list.append(atom.rx)
|
|
||||||
y_list.append(atom.ry)
|
|
||||||
z_list.append(atom.rz)
|
|
||||||
|
|
||||||
x_max = max(x_list)
|
|
||||||
x_min = min(x_list)
|
|
||||||
y_max = max(y_list)
|
|
||||||
y_min = min(y_list)
|
|
||||||
z_max = max(z_list)
|
|
||||||
z_min = min(z_list)
|
|
||||||
|
|
||||||
sizes = [x_max - x_min, y_max - y_min, z_max - z_min]
|
|
||||||
|
|
||||||
return sizes
|
|
||||||
|
|
||||||
def standard_orientation(self) -> None:
|
|
||||||
"""
|
|
||||||
Rotates the molecule to the standard orientation
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.center_of_mass_to_origin()
|
|
||||||
evals, evecs = self.principal_axes()
|
|
||||||
|
|
||||||
if round(linalg.det(evecs)) == -1:
|
|
||||||
evecs[0, 2] *= -1
|
|
||||||
evecs[1, 2] *= -1
|
|
||||||
evecs[2, 2] *= -1
|
|
||||||
|
|
||||||
if round(linalg.det(evecs)) != 1:
|
|
||||||
raise RuntimeError(
|
|
||||||
"Error: could not make a rotation matrix while adopting the standard orientation"
|
|
||||||
)
|
|
||||||
|
|
||||||
rot_matrix = evecs.T
|
|
||||||
|
|
||||||
for atom in self.atom:
|
|
||||||
position = np.array([atom.rx, atom.ry, atom.rz])
|
|
||||||
new_position = np.matmul(rot_matrix, position.T).T
|
|
||||||
|
|
||||||
atom.rx = new_position[0]
|
|
||||||
atom.ry = new_position[1]
|
|
||||||
atom.rz = new_position[2]
|
|
||||||
|
|
||||||
def translate(self, vector: np.ndarray) -> "Molecule":
|
|
||||||
"""
|
|
||||||
Creates a new Molecule object where its' atoms has been translated by a vector
|
|
||||||
|
|
||||||
Args:
|
|
||||||
vector (np.ndarray): translation vector
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Molecule: new Molecule object translated by a vector
|
|
||||||
"""
|
|
||||||
|
|
||||||
new_molecule = deepcopy(self)
|
|
||||||
|
|
||||||
for atom in new_molecule.atom:
|
|
||||||
atom.rx += vector[0]
|
|
||||||
atom.ry += vector[1]
|
|
||||||
atom.rz += vector[2]
|
|
||||||
|
|
||||||
return new_molecule
|
|
||||||
|
|
||||||
def print_mol_info(self) -> None:
|
|
||||||
"""
|
|
||||||
Prints the Molecule information into a Output File
|
|
||||||
"""
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
" Center of mass = ( {:>10.4f} , {:>10.4f} , {:>10.4f} )".format(
|
|
||||||
self.com[0], self.com[1], self.com[2]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
inertia = self.inertia_tensor()
|
|
||||||
evals, evecs = self.principal_axes()
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
" Moments of inertia = {:>9E} {:>9E} {:>9E}".format(
|
|
||||||
evals[0], evals[1], evals[2]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
" Major principal axis = ( {:>10.6f} , {:>10.6f} , {:>10.6f} )".format(
|
|
||||||
evecs[0, 0], evecs[1, 0], evecs[2, 0]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
" Inter principal axis = ( {:>10.6f} , {:>10.6f} , {:>10.6f} )".format(
|
|
||||||
evecs[0, 1], evecs[1, 1], evecs[2, 1]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
logger.info(
|
|
||||||
" Minor principal axis = ( {:>10.6f} , {:>10.6f} , {:>10.6f} )".format(
|
|
||||||
evecs[0, 2], evecs[1, 2], evecs[2, 2]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
sizes = self.sizes_of_molecule()
|
|
||||||
logger.info(
|
|
||||||
" Characteristic lengths = ( {:>6.2f} , {:>6.2f} , {:>6.2f} )".format(
|
|
||||||
sizes[0], sizes[1], sizes[2]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
logger.info(" Total mass = {:>8.2f} au".format(self.total_mass))
|
|
||||||
|
|
||||||
chg_dip = self.charges_and_dipole()
|
|
||||||
logger.info(" Total charge = {:>8.4f} e".format(chg_dip[0]))
|
|
||||||
logger.info(
|
|
||||||
" Dipole moment = ( {:>9.4f} , {:>9.4f} , {:>9.4f} ) Total = {:>9.4f} Debye".format(
|
|
||||||
chg_dip[1], chg_dip[2], chg_dip[3], chg_dip[4]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def minimum_distance(self, molec: "Molecule") -> float:
|
|
||||||
"""
|
|
||||||
Return the minimum distance between two molecules
|
|
||||||
|
|
||||||
Args:
|
|
||||||
molec (Molecule): Molecule object to be compared
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
float: minimum distance between the two molecules
|
|
||||||
"""
|
|
||||||
|
|
||||||
distances = []
|
|
||||||
for atom1 in self.atom:
|
|
||||||
if atom1.na != ghost_number:
|
|
||||||
for atom2 in molec.atom:
|
|
||||||
if atom2.na != ghost_number:
|
|
||||||
dx = atom1.rx - atom2.rx
|
|
||||||
dy = atom1.ry - atom2.ry
|
|
||||||
dz = atom1.rz - atom2.rz
|
|
||||||
distances.append(math.sqrt(dx**2 + dy**2 + dz**2))
|
|
||||||
|
|
||||||
return min(distances)
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
from diceplayer import logger
|
|
||||||
from diceplayer.shared.environment.molecule import Molecule
|
|
||||||
from diceplayer.shared.utils.misc import BOHR2ANG
|
|
||||||
from diceplayer.shared.utils.ptable import atomsymb
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from numpy import linalg
|
|
||||||
|
|
||||||
import math
|
|
||||||
from copy import deepcopy
|
|
||||||
from typing import List, TextIO, Tuple
|
|
||||||
|
|
||||||
|
|
||||||
class System:
|
|
||||||
"""
|
|
||||||
System class declaration. This class is used throughout the DicePlayer program to represent the system containing the molecules.
|
|
||||||
|
|
||||||
Atributes:
|
|
||||||
molecule (List[Molecule]): List of molecules of the system
|
|
||||||
nmols (List[int]): List of number of molecules in the system
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""
|
|
||||||
Initializes an empty system object that will be populated afterwards
|
|
||||||
"""
|
|
||||||
self.nmols: List[int] = []
|
|
||||||
self.molecule: List[Molecule] = []
|
|
||||||
|
|
||||||
def add_type(self, m: Molecule) -> None:
|
|
||||||
"""
|
|
||||||
Adds a new molecule type to the system
|
|
||||||
|
|
||||||
Args:
|
|
||||||
m (Molecule): The instance of the new type of molecule
|
|
||||||
"""
|
|
||||||
if isinstance(m, Molecule) is False:
|
|
||||||
raise TypeError("Error: molecule is not a Molecule instance")
|
|
||||||
self.molecule.append(m)
|
|
||||||
|
|
||||||
def update_molecule(self, position: np.ndarray) -> None:
|
|
||||||
"""Updates the position of the molecule in the Output file
|
|
||||||
|
|
||||||
Args:
|
|
||||||
position (np.ndarray): numpy position vector
|
|
||||||
"""
|
|
||||||
|
|
||||||
position_in_ang = (position * BOHR2ANG).tolist()
|
|
||||||
self.add_type(deepcopy(self.molecule[0]))
|
|
||||||
|
|
||||||
for atom in self.molecule[-1].atom:
|
|
||||||
atom.rx = position_in_ang.pop(0)
|
|
||||||
atom.ry = position_in_ang.pop(0)
|
|
||||||
atom.rz = position_in_ang.pop(0)
|
|
||||||
|
|
||||||
rmsd, self.molecule[0] = self.rmsd_fit(-1, 0)
|
|
||||||
self.molecule.pop(-1)
|
|
||||||
|
|
||||||
logger.info("Projected new conformation of reference molecule with RMSD fit")
|
|
||||||
logger.info(f"RMSD = {rmsd:>8.5f} Angstrom")
|
|
||||||
|
|
||||||
def rmsd_fit(self, p_index: int, r_index: int) -> Tuple[float, Molecule]:
|
|
||||||
projecting_mol = self.molecule[p_index]
|
|
||||||
reference_mol = self.molecule[r_index]
|
|
||||||
|
|
||||||
if len(projecting_mol.atom) != len(reference_mol.atom):
|
|
||||||
raise RuntimeError(
|
|
||||||
"Error in RMSD fit procedure: molecules have different number of atoms"
|
|
||||||
)
|
|
||||||
dim = len(projecting_mol.atom)
|
|
||||||
|
|
||||||
new_projecting_mol = deepcopy(projecting_mol)
|
|
||||||
new_reference_mol = deepcopy(reference_mol)
|
|
||||||
|
|
||||||
new_projecting_mol.center_of_mass_to_origin()
|
|
||||||
new_reference_mol.center_of_mass_to_origin()
|
|
||||||
|
|
||||||
x = []
|
|
||||||
y = []
|
|
||||||
|
|
||||||
for atom in new_projecting_mol.atom:
|
|
||||||
x.extend([atom.rx, atom.ry, atom.rz])
|
|
||||||
|
|
||||||
for atom in new_reference_mol.atom:
|
|
||||||
y.extend([atom.rx, atom.ry, atom.rz])
|
|
||||||
|
|
||||||
x = np.array(x).reshape(dim, 3)
|
|
||||||
y = np.array(y).reshape(dim, 3)
|
|
||||||
|
|
||||||
r = np.matmul(y.T, x)
|
|
||||||
rr = np.matmul(r.T, r)
|
|
||||||
|
|
||||||
try:
|
|
||||||
evals, evecs = linalg.eigh(rr)
|
|
||||||
except:
|
|
||||||
raise RuntimeError("Error: diagonalization of RR matrix did not converge")
|
|
||||||
|
|
||||||
a1 = evecs[:, 2].T
|
|
||||||
a2 = evecs[:, 1].T
|
|
||||||
a3 = np.cross(a1, a2)
|
|
||||||
|
|
||||||
A = np.array([a1[0], a1[1], a1[2], a2[0], a2[1], a2[2], a3[0], a3[1], a3[2]])
|
|
||||||
A = A.reshape(3, 3)
|
|
||||||
|
|
||||||
b1 = np.matmul(r, a1.T).T # or np.dot(r, a1)
|
|
||||||
b1 /= linalg.norm(b1)
|
|
||||||
b2 = np.matmul(r, a2.T).T # or np.dot(r, a2)
|
|
||||||
b2 /= linalg.norm(b2)
|
|
||||||
b3 = np.cross(b1, b2)
|
|
||||||
|
|
||||||
B = np.array([b1[0], b1[1], b1[2], b2[0], b2[1], b2[2], b3[0], b3[1], b3[2]])
|
|
||||||
B = B.reshape(3, 3).T
|
|
||||||
|
|
||||||
rot_matrix = np.matmul(B, A)
|
|
||||||
x = np.matmul(rot_matrix, x.T).T
|
|
||||||
|
|
||||||
rmsd = 0
|
|
||||||
for i in range(dim):
|
|
||||||
rmsd += (
|
|
||||||
(x[i, 0] - y[i, 0]) ** 2
|
|
||||||
+ (x[i, 1] - y[i, 1]) ** 2
|
|
||||||
+ (x[i, 2] - y[i, 2]) ** 2
|
|
||||||
)
|
|
||||||
rmsd = math.sqrt(rmsd / dim)
|
|
||||||
|
|
||||||
for i in range(dim):
|
|
||||||
new_projecting_mol.atom[i].rx = x[i, 0]
|
|
||||||
new_projecting_mol.atom[i].ry = x[i, 1]
|
|
||||||
new_projecting_mol.atom[i].rz = x[i, 2]
|
|
||||||
|
|
||||||
reference_mol.center_of_mass()
|
|
||||||
|
|
||||||
projected_mol = new_projecting_mol.translate(reference_mol.com)
|
|
||||||
|
|
||||||
return rmsd, projected_mol
|
|
||||||
|
|
||||||
# def center_of_mass_distance(self, a: int, b: int) -> float:
|
|
||||||
# """
|
|
||||||
# Calculates the distance between the center of mass of two molecules
|
|
||||||
#
|
|
||||||
# Args:
|
|
||||||
# a (Molecule): First Molecule Instance
|
|
||||||
# b (Molecule): Second Molecule Instance
|
|
||||||
#
|
|
||||||
# Returns:
|
|
||||||
# float: module of the distance between the two center of masses
|
|
||||||
# """
|
|
||||||
#
|
|
||||||
# com1 = self.molecule[a].center_of_mass()
|
|
||||||
# com2 = self.molecule[b].center_of_mass()
|
|
||||||
# dx = com1[0] - com2[0]
|
|
||||||
# dy = com1[1] - com2[1]
|
|
||||||
# dz = com1[2] - com2[2]
|
|
||||||
# distance = math.sqrt(dx**2 + dy**2 + dz**2)
|
|
||||||
#
|
|
||||||
# return distance
|
|
||||||
|
|
||||||
# def nearest_image(
|
|
||||||
# self,
|
|
||||||
# index_r: int,
|
|
||||||
# index_m: int,
|
|
||||||
# lx: float,
|
|
||||||
# ly: float,
|
|
||||||
# lz: float,
|
|
||||||
# criterium=None,
|
|
||||||
# ) -> Tuple[float, Molecule]:
|
|
||||||
#
|
|
||||||
# if criterium in None:
|
|
||||||
# criterium = "com"
|
|
||||||
#
|
|
||||||
# if criterium != "com" and criterium != "min":
|
|
||||||
# raise RuntimeError("Error in value passed to function nearest_image")
|
|
||||||
#
|
|
||||||
# min_dist = 1e20
|
|
||||||
#
|
|
||||||
# for i in range(-1, 2):
|
|
||||||
# for j in range(-1, 2):
|
|
||||||
# for k in range(-1, 2):
|
|
||||||
#
|
|
||||||
# tr_vector = [i * lx, j * ly, k * lz]
|
|
||||||
# self.add_molecule(self.molecule[index_m].translate(tr_vector))
|
|
||||||
#
|
|
||||||
# if criterium == "com":
|
|
||||||
# dist = self.center_of_mass_distance(index_r, -1)
|
|
||||||
# else:
|
|
||||||
# dist = self.minimum_distance(index_r, -1)
|
|
||||||
#
|
|
||||||
# if dist < min_dist:
|
|
||||||
# min_dist = dist
|
|
||||||
# nearestmol = deepcopy(self.molecule[-1])
|
|
||||||
#
|
|
||||||
# self.molecule.pop(-1)
|
|
||||||
#
|
|
||||||
# return min_dist, nearestmol
|
|
||||||
|
|
||||||
# def print_geom(self, cycle: int, fh: TextIO) -> None:
|
|
||||||
# """
|
|
||||||
# Print the geometry of the molecule in the Output file
|
|
||||||
#
|
|
||||||
# Args:
|
|
||||||
# cycle (int): Number of the cycle
|
|
||||||
# fh (TextIO): Output file
|
|
||||||
# """
|
|
||||||
#
|
|
||||||
# fh.write("Cycle # {}\n".format(cycle))
|
|
||||||
# fh.write("Number of site: {}\n".format(len(self.molecule[0].atom)))
|
|
||||||
# for atom in self.molecule[0].atom:
|
|
||||||
# symbol = atomsymb[atom.na]
|
|
||||||
# fh.write(
|
|
||||||
# "{:<2s} {:>10.6f} {:>10.6f} {:>10.6f}\n".format(
|
|
||||||
# symbol, atom.rx, atom.ry, atom.rz
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
def print_charges_and_dipole(self, cycle: int) -> None:
|
|
||||||
"""
|
|
||||||
Print the charges and dipole of the molecule in the Output file
|
|
||||||
|
|
||||||
Args:
|
|
||||||
cycle (int): Number of the cycle
|
|
||||||
fh (TextIO): Output file
|
|
||||||
"""
|
|
||||||
|
|
||||||
logger.info("Cycle # {}\n".format(cycle))
|
|
||||||
logger.info("Number of site: {}\n".format(len(self.molecule[0].atom)))
|
|
||||||
|
|
||||||
chargesAndDipole = self.molecule[0].charges_and_dipole()
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
"{:>10.6f} {:>10.6f} {:>10.6f} {:>10.6f} {:>10.6f}\n".format(
|
|
||||||
chargesAndDipole[0],
|
|
||||||
chargesAndDipole[1],
|
|
||||||
chargesAndDipole[2],
|
|
||||||
chargesAndDipole[3],
|
|
||||||
chargesAndDipole[4],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .__interface import Interface
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
|
|
||||||
|
|
||||||
class Interface(ABC):
|
|
||||||
__slots__ = ["step", "system"]
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.system: System | None = None
|
|
||||||
self.step: PlayerConfig | None = None
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def configure(self, step: PlayerConfig, system: System):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def start(self, cycle: int):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def reset(self):
|
|
||||||
pass
|
|
||||||
@@ -1,387 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from diceplayer import logger
|
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
from diceplayer.shared.interface import Interface
|
|
||||||
|
|
||||||
from setproctitle import setproctitle
|
|
||||||
|
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from multiprocessing import Process, connection
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Final, TextIO
|
|
||||||
|
|
||||||
DICE_END_FLAG: Final[str] = "End of simulation"
|
|
||||||
DICE_FLAG_LINE: Final[int] = -2
|
|
||||||
UMAANG3_TO_GCM3: Final[float] = 1.6605
|
|
||||||
|
|
||||||
MAX_SEED: Final[int] = 4294967295
|
|
||||||
|
|
||||||
|
|
||||||
class DiceInterface(Interface):
|
|
||||||
title = "Diceplayer run"
|
|
||||||
|
|
||||||
def configure(self, step: PlayerConfig, system: System):
|
|
||||||
self.step = step
|
|
||||||
self.system = system
|
|
||||||
|
|
||||||
def start(self, cycle: int):
|
|
||||||
procs = []
|
|
||||||
sentinels = []
|
|
||||||
|
|
||||||
for proc in range(1, self.step.nprocs + 1):
|
|
||||||
p = Process(target=self._simulation_process, args=(cycle, proc))
|
|
||||||
p.start()
|
|
||||||
|
|
||||||
procs.append(p)
|
|
||||||
sentinels.append(p.sentinel)
|
|
||||||
|
|
||||||
while procs:
|
|
||||||
finished = connection.wait(sentinels)
|
|
||||||
for proc_sentinel in finished:
|
|
||||||
i = sentinels.index(proc_sentinel)
|
|
||||||
status = procs[i].exitcode
|
|
||||||
procs.pop(i)
|
|
||||||
sentinels.pop(i)
|
|
||||||
if status != 0:
|
|
||||||
for p in procs:
|
|
||||||
p.terminate()
|
|
||||||
sys.exit(status)
|
|
||||||
|
|
||||||
logger.info("\n")
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
del self.step
|
|
||||||
del self.system
|
|
||||||
|
|
||||||
def _simulation_process(self, cycle: int, proc: int):
|
|
||||||
setproctitle(f"diceplayer-step{cycle:0d}-p{proc:0d}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
self._make_proc_dir(cycle, proc)
|
|
||||||
self._make_dice_inputs(cycle, proc)
|
|
||||||
self._run_dice(cycle, proc)
|
|
||||||
except Exception as err:
|
|
||||||
sys.exit(err)
|
|
||||||
|
|
||||||
def _make_proc_dir(self, cycle, proc):
|
|
||||||
simulation_dir = Path(self.step.simulation_dir)
|
|
||||||
if not simulation_dir.exists():
|
|
||||||
simulation_dir.mkdir(parents=True)
|
|
||||||
|
|
||||||
proc_dir = Path(simulation_dir, f"step{cycle:02d}", f"p{proc:02d}")
|
|
||||||
proc_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
def _make_dice_inputs(self, cycle, proc):
|
|
||||||
proc_dir = Path(self.step.simulation_dir, f"step{cycle:02d}", f"p{proc:02d}")
|
|
||||||
|
|
||||||
self._make_potentials(proc_dir)
|
|
||||||
|
|
||||||
random.seed(self._make_dice_seed())
|
|
||||||
|
|
||||||
# This is logic is used to make the initial configuration file
|
|
||||||
# for the next cycle using the last.xyz file from the previous cycle.
|
|
||||||
if self.step.dice.randominit == "first" and cycle > 1:
|
|
||||||
last_xyz = Path(
|
|
||||||
self.step.simulation_dir,
|
|
||||||
f"step{(cycle - 1):02d}",
|
|
||||||
f"p{proc:02d}",
|
|
||||||
"last.xyz",
|
|
||||||
)
|
|
||||||
if not last_xyz.exists():
|
|
||||||
raise FileNotFoundError(f"File {last_xyz} not found.")
|
|
||||||
|
|
||||||
with open(last_xyz, "r") as last_xyz_file:
|
|
||||||
self._make_init_file(proc_dir, last_xyz_file)
|
|
||||||
last_xyz_file.seek(0)
|
|
||||||
self.step.dice.dens = self._new_density(last_xyz_file)
|
|
||||||
|
|
||||||
else:
|
|
||||||
self._make_nvt_ter(cycle, proc_dir)
|
|
||||||
|
|
||||||
if len(self.step.dice.nstep) == 2:
|
|
||||||
self._make_nvt_eq(cycle, proc_dir)
|
|
||||||
|
|
||||||
elif len(self.step.dice.nstep) == 3:
|
|
||||||
self._make_npt_ter(cycle, proc_dir)
|
|
||||||
self._make_npt_eq(proc_dir)
|
|
||||||
|
|
||||||
def _run_dice(self, cycle: int, proc: int):
|
|
||||||
working_dir = os.getcwd()
|
|
||||||
|
|
||||||
proc_dir = Path(self.step.simulation_dir, f"step{cycle:02d}", f"p{proc:02d}")
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
f"Simulation process {str(proc_dir)} initiated with pid {os.getpid()}"
|
|
||||||
)
|
|
||||||
|
|
||||||
os.chdir(proc_dir)
|
|
||||||
|
|
||||||
if not (self.step.dice.randominit == "first" and cycle > 1):
|
|
||||||
self.run_dice_file(cycle, proc, "NVT.ter")
|
|
||||||
|
|
||||||
if len(self.step.dice.nstep) == 2:
|
|
||||||
self.run_dice_file(cycle, proc, "NVT.eq")
|
|
||||||
|
|
||||||
elif len(self.step.dice.nstep) == 3:
|
|
||||||
self.run_dice_file(cycle, proc, "NPT.ter")
|
|
||||||
self.run_dice_file(cycle, proc, "NPT.eq")
|
|
||||||
|
|
||||||
os.chdir(working_dir)
|
|
||||||
|
|
||||||
xyz_file = Path(proc_dir, "phb.xyz")
|
|
||||||
last_xyz_file = Path(proc_dir, "last.xyz")
|
|
||||||
|
|
||||||
if xyz_file.exists():
|
|
||||||
shutil.copy(xyz_file, last_xyz_file)
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError(f"File {xyz_file} not found.")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _make_dice_seed() -> int:
|
|
||||||
num = time.time()
|
|
||||||
num = (num - int(num)) * 1e6
|
|
||||||
|
|
||||||
num = int((num - int(num)) * 1e6)
|
|
||||||
|
|
||||||
return (os.getpid() * num) % (MAX_SEED + 1)
|
|
||||||
|
|
||||||
def _make_init_file(self, proc_dir: Path, last_xyz_file: TextIO):
|
|
||||||
xyz_lines = last_xyz_file.readlines()
|
|
||||||
|
|
||||||
SECONDARY_MOLECULE_LENGTH = 0
|
|
||||||
for i in range(1, len(self.step.dice.nmol)):
|
|
||||||
SECONDARY_MOLECULE_LENGTH += self.step.dice.nmol[i] * len(
|
|
||||||
self.system.molecule[i].atom
|
|
||||||
)
|
|
||||||
|
|
||||||
xyz_lines = xyz_lines[-SECONDARY_MOLECULE_LENGTH:]
|
|
||||||
|
|
||||||
input_file = Path(proc_dir, self.step.dice.outname + ".xy")
|
|
||||||
with open(input_file, "w") as f:
|
|
||||||
for atom in self.system.molecule[0].atom:
|
|
||||||
f.write(f"{atom.rx:>10.6f} {atom.ry:>10.6f} {atom.rz:>10.6f}\n")
|
|
||||||
|
|
||||||
for line in xyz_lines:
|
|
||||||
atom = line.split()
|
|
||||||
rx = float(atom[1])
|
|
||||||
ry = float(atom[2])
|
|
||||||
rz = float(atom[3])
|
|
||||||
f.write(f"{rx:>10.6f} {ry:>10.6f} {rz:>10.6f}\n")
|
|
||||||
|
|
||||||
f.write("$end")
|
|
||||||
|
|
||||||
def _new_density(self, last_xyz_file: TextIO):
|
|
||||||
last_xyz_lines = last_xyz_file.readlines()
|
|
||||||
|
|
||||||
box = last_xyz_lines[1].split()
|
|
||||||
volume = float(box[-3]) * float(box[-2]) * float(box[-1])
|
|
||||||
|
|
||||||
total_mass = 0
|
|
||||||
for i in range(len(self.system.molecule)):
|
|
||||||
total_mass += self.system.molecule[i].total_mass * self.step.dice.nmol[i]
|
|
||||||
|
|
||||||
density = (total_mass / volume) * UMAANG3_TO_GCM3
|
|
||||||
|
|
||||||
return density
|
|
||||||
|
|
||||||
def _make_nvt_ter(self, cycle, proc_dir):
|
|
||||||
file = Path(proc_dir, "NVT.ter")
|
|
||||||
with open(file, "w") as f:
|
|
||||||
f.write(f"title = {self.title} - NVT Thermalization\n")
|
|
||||||
f.write(f"ncores = {self.step.ncores}\n")
|
|
||||||
f.write(f"ljname = {self.step.dice.ljname}\n")
|
|
||||||
f.write(f"outname = {self.step.dice.outname}\n")
|
|
||||||
|
|
||||||
mol_string = " ".join(str(x) for x in self.step.dice.nmol)
|
|
||||||
f.write(f"nmol = {mol_string}\n")
|
|
||||||
|
|
||||||
f.write(f"dens = {self.step.dice.dens}\n")
|
|
||||||
f.write(f"temp = {self.step.dice.temp}\n")
|
|
||||||
|
|
||||||
if self.step.dice.randominit == "first" and cycle > 1:
|
|
||||||
f.write(f"init = yesreadxyz\n")
|
|
||||||
f.write(f"nstep = {self.step.altsteps}\n")
|
|
||||||
else:
|
|
||||||
f.write(f"init = yes\n")
|
|
||||||
f.write(f"nstep = {self.step.dice.nstep[0]}\n")
|
|
||||||
|
|
||||||
f.write("vstep = 0\n")
|
|
||||||
f.write("mstop = 1\n")
|
|
||||||
f.write("accum = no\n")
|
|
||||||
f.write("iprint = 1\n")
|
|
||||||
f.write("isave = 0\n")
|
|
||||||
f.write("irdf = 0\n")
|
|
||||||
|
|
||||||
seed = int(1e6 * random.random())
|
|
||||||
f.write(f"seed = {seed}\n")
|
|
||||||
f.write(f"upbuf = {self.step.dice.upbuf}")
|
|
||||||
|
|
||||||
def _make_nvt_eq(self, cycle, proc_dir):
|
|
||||||
file = Path(proc_dir, "NVT.eq")
|
|
||||||
with open(file, "w") as f:
|
|
||||||
f.write(f"title = {self.title} - NVT Production\n")
|
|
||||||
f.write(f"ncores = {self.step.ncores}\n")
|
|
||||||
f.write(f"ljname = {self.step.dice.ljname}\n")
|
|
||||||
f.write(f"outname = {self.step.dice.outname}\n")
|
|
||||||
|
|
||||||
mol_string = " ".join(str(x) for x in self.step.dice.nmol)
|
|
||||||
f.write(f"nmol = {mol_string}\n")
|
|
||||||
|
|
||||||
f.write(f"dens = {self.step.dice.dens}\n")
|
|
||||||
f.write(f"temp = {self.step.dice.temp}\n")
|
|
||||||
|
|
||||||
if self.step.dice.randominit == "first" and cycle > 1:
|
|
||||||
f.write("init = yesreadxyz\n")
|
|
||||||
else:
|
|
||||||
f.write("init = no\n")
|
|
||||||
|
|
||||||
f.write(f"nstep = {self.step.dice.nstep[1]}\n")
|
|
||||||
|
|
||||||
f.write("vstep = 0\n")
|
|
||||||
f.write("mstop = 1\n")
|
|
||||||
f.write("accum = no\n")
|
|
||||||
f.write("iprint = 1\n")
|
|
||||||
|
|
||||||
f.write(f"isave = {self.step.dice.isave}\n")
|
|
||||||
f.write(f"irdf = {10 * self.step.nprocs}\n")
|
|
||||||
|
|
||||||
seed = int(1e6 * random.random())
|
|
||||||
f.write("seed = {}\n".format(seed))
|
|
||||||
|
|
||||||
def _make_npt_ter(self, cycle, proc_dir):
|
|
||||||
file = Path(proc_dir, "NPT.ter")
|
|
||||||
with open(file, "w") as f:
|
|
||||||
f.write(f"title = {self.title} - NPT Thermalization\n")
|
|
||||||
f.write(f"ncores = {self.step.ncores}\n")
|
|
||||||
f.write(f"ljname = {self.step.dice.ljname}\n")
|
|
||||||
f.write(f"outname = {self.step.dice.outname}\n")
|
|
||||||
|
|
||||||
mol_string = " ".join(str(x) for x in self.step.dice.nmol)
|
|
||||||
f.write(f"nmol = {mol_string}\n")
|
|
||||||
|
|
||||||
f.write(f"press = {self.step.dice.press}\n")
|
|
||||||
f.write(f"temp = {self.step.dice.temp}\n")
|
|
||||||
|
|
||||||
if self.step.dice.randominit == "first" and cycle > 1:
|
|
||||||
f.write("init = yesreadxyz\n")
|
|
||||||
f.write(f"dens = {self.step.dice.dens:<8.4f}\n")
|
|
||||||
f.write(f"vstep = {int(self.step.altsteps / 5)}\n")
|
|
||||||
else:
|
|
||||||
f.write("init = no\n")
|
|
||||||
f.write(f"vstep = {int(self.step.dice.nstep[1] / 5)}\n")
|
|
||||||
|
|
||||||
f.write("nstep = 5\n")
|
|
||||||
f.write("mstop = 1\n")
|
|
||||||
f.write("accum = no\n")
|
|
||||||
f.write("iprint = 1\n")
|
|
||||||
f.write("isave = 0\n")
|
|
||||||
f.write("irdf = 0\n")
|
|
||||||
|
|
||||||
seed = int(1e6 * random.random())
|
|
||||||
f.write(f"seed = {seed}\n")
|
|
||||||
|
|
||||||
def _make_npt_eq(self, proc_dir):
|
|
||||||
file = Path(proc_dir, "NPT.eq")
|
|
||||||
with open(file, "w") as f:
|
|
||||||
f.write(f"title = {self.title} - NPT Production\n")
|
|
||||||
f.write(f"ncores = {self.step.ncores}\n")
|
|
||||||
f.write(f"ljname = {self.step.dice.ljname}\n")
|
|
||||||
f.write(f"outname = {self.step.dice.outname}\n")
|
|
||||||
|
|
||||||
mol_string = " ".join(str(x) for x in self.step.dice.nmol)
|
|
||||||
f.write(f"nmol = {mol_string}\n")
|
|
||||||
|
|
||||||
f.write(f"press = {self.step.dice.press}\n")
|
|
||||||
f.write(f"temp = {self.step.dice.temp}\n")
|
|
||||||
|
|
||||||
f.write(f"nstep = 5\n")
|
|
||||||
|
|
||||||
f.write(f"vstep = {int(self.step.dice.nstep[2] / 5)}\n")
|
|
||||||
f.write("init = no\n")
|
|
||||||
f.write("mstop = 1\n")
|
|
||||||
f.write("accum = no\n")
|
|
||||||
f.write("iprint = 1\n")
|
|
||||||
f.write(f"isave = {self.step.dice.isave}\n")
|
|
||||||
f.write(f"irdf = {10 * self.step.nprocs}\n")
|
|
||||||
|
|
||||||
seed = int(1e6 * random.random())
|
|
||||||
f.write(f"seed = {seed}\n")
|
|
||||||
|
|
||||||
def _make_potentials(self, proc_dir):
|
|
||||||
fstr = "{:<3d} {:>3d} {:>10.5f} {:>10.5f} {:>10.5f} {:>10.6f} {:>9.5f} {:>7.4f}\n"
|
|
||||||
|
|
||||||
file = Path(proc_dir, self.step.dice.ljname)
|
|
||||||
with open(file, "w") as f:
|
|
||||||
f.write(f"{self.step.dice.combrule}\n")
|
|
||||||
f.write(f"{len(self.step.dice.nmol)}\n")
|
|
||||||
|
|
||||||
nsites_qm = len(self.system.molecule[0].atom)
|
|
||||||
f.write(f"{nsites_qm} {self.system.molecule[0].molname}\n")
|
|
||||||
|
|
||||||
for atom in self.system.molecule[0].atom:
|
|
||||||
f.write(
|
|
||||||
fstr.format(
|
|
||||||
atom.lbl,
|
|
||||||
atom.na,
|
|
||||||
atom.rx,
|
|
||||||
atom.ry,
|
|
||||||
atom.rz,
|
|
||||||
atom.chg,
|
|
||||||
atom.eps,
|
|
||||||
atom.sig,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
for mol in self.system.molecule[1:]:
|
|
||||||
f.write(f"{len(mol.atom)} {mol.molname}\n")
|
|
||||||
for atom in mol.atom:
|
|
||||||
f.write(
|
|
||||||
fstr.format(
|
|
||||||
atom.lbl,
|
|
||||||
atom.na,
|
|
||||||
atom.rx,
|
|
||||||
atom.ry,
|
|
||||||
atom.rz,
|
|
||||||
atom.chg,
|
|
||||||
atom.eps,
|
|
||||||
atom.sig,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def run_dice_file(self, cycle: int, proc: int, file_name: str):
|
|
||||||
with open(Path(file_name), "r") as infile, open(
|
|
||||||
Path(file_name + ".out"), "w"
|
|
||||||
) as outfile:
|
|
||||||
if shutil.which("bash") is not None:
|
|
||||||
exit_status = subprocess.call(
|
|
||||||
[
|
|
||||||
"bash",
|
|
||||||
"-c",
|
|
||||||
f"exec -a dice-step{cycle}-p{proc} {self.step.dice.progname} < {infile.name} > {outfile.name}",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
exit_status = subprocess.call(
|
|
||||||
self.step.dice.progname, stdin=infile, stdout=outfile
|
|
||||||
)
|
|
||||||
|
|
||||||
if exit_status != 0:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Dice process step{cycle:02d}-p{proc:02d} did not exit properly"
|
|
||||||
)
|
|
||||||
|
|
||||||
with open(Path(file_name + ".out"), "r") as outfile:
|
|
||||||
flag = outfile.readlines()[DICE_FLAG_LINE].strip()
|
|
||||||
if flag != DICE_END_FLAG:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Dice process step{cycle:02d}-p{proc:02d} did not exit properly"
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(f"Dice {file_name} - step{cycle:02d}-p{proc:02d} exited properly")
|
|
||||||
@@ -1,359 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from diceplayer import logger
|
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
|
||||||
from diceplayer.shared.environment.atom import Atom
|
|
||||||
from diceplayer.shared.environment.molecule import Molecule
|
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
from diceplayer.shared.interface import Interface
|
|
||||||
from diceplayer.shared.utils.misc import date_time
|
|
||||||
from diceplayer.shared.utils.ptable import atomsymb
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from nptyping import NDArray
|
|
||||||
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
import textwrap
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List, Tuple
|
|
||||||
|
|
||||||
|
|
||||||
class GaussianInterface(Interface):
|
|
||||||
def configure(self, step_dto: PlayerConfig, system: System):
|
|
||||||
self.system = system
|
|
||||||
self.step = step_dto
|
|
||||||
|
|
||||||
def start(self, cycle: int) -> Dict[str, NDArray]:
|
|
||||||
self._make_qm_dir(cycle)
|
|
||||||
|
|
||||||
if cycle > 1:
|
|
||||||
self._copy_chk_file_from_previous_step(cycle)
|
|
||||||
|
|
||||||
asec_charges = self.populate_asec_vdw(cycle)
|
|
||||||
self._make_gaussian_input_file(cycle, asec_charges)
|
|
||||||
|
|
||||||
self._run_gaussian(cycle)
|
|
||||||
self._run_formchk(cycle)
|
|
||||||
|
|
||||||
return_value = {}
|
|
||||||
if self.step.opt:
|
|
||||||
# return_value['position'] = np.array(
|
|
||||||
# self._run_optimization(cycle)
|
|
||||||
# )
|
|
||||||
raise NotImplementedError("Optimization not implemented yet.")
|
|
||||||
|
|
||||||
else:
|
|
||||||
return_value["charges"] = np.array(self._read_charges_from_fchk(cycle))
|
|
||||||
|
|
||||||
return return_value
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
del self.step
|
|
||||||
del self.system
|
|
||||||
|
|
||||||
def _make_qm_dir(self, cycle: int):
|
|
||||||
qm_dir_path = Path(self.step.simulation_dir, f"step{cycle:02d}", "qm")
|
|
||||||
if not qm_dir_path.exists():
|
|
||||||
qm_dir_path.mkdir()
|
|
||||||
|
|
||||||
def _copy_chk_file_from_previous_step(self, cycle: int):
|
|
||||||
current_chk_file_path = Path(
|
|
||||||
self.step.simulation_dir, f"step{cycle:02d}", "qm", f"asec.chk"
|
|
||||||
)
|
|
||||||
if current_chk_file_path.exists():
|
|
||||||
raise FileExistsError(f"File {current_chk_file_path} already exists.")
|
|
||||||
|
|
||||||
previous_chk_file_path = Path(
|
|
||||||
self.step.simulation_dir, f"step{(cycle - 1):02d}", "qm", f"asec.chk"
|
|
||||||
)
|
|
||||||
if not previous_chk_file_path.exists():
|
|
||||||
raise FileNotFoundError(f"File {previous_chk_file_path} does not exist.")
|
|
||||||
|
|
||||||
shutil.copy(previous_chk_file_path, current_chk_file_path)
|
|
||||||
|
|
||||||
def populate_asec_vdw(self, cycle: int) -> list[dict]:
|
|
||||||
norm_factor = self._calculate_norm_factor()
|
|
||||||
|
|
||||||
nsitesref = len(self.system.molecule[0].atom)
|
|
||||||
|
|
||||||
nsites_total = self._calculate_total_number_of_sites(nsitesref)
|
|
||||||
|
|
||||||
proc_charges = []
|
|
||||||
for proc in range(1, self.step.nprocs + 1):
|
|
||||||
proc_charges.append(self._read_charges_from_last_step(cycle, proc))
|
|
||||||
|
|
||||||
asec_charges, thickness, picked_mols = self._evaluate_proc_charges(
|
|
||||||
nsites_total, proc_charges
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
f"In average, {(sum(picked_mols) / norm_factor):^7.2f} molecules\n"
|
|
||||||
f"were selected from each of the {len(picked_mols)} configurations\n"
|
|
||||||
f"of the production simulations to form the ASEC, comprising a shell with\n"
|
|
||||||
f"minimum thickness of {(sum(thickness) / norm_factor):>6.2f} Angstrom\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
for charge in asec_charges:
|
|
||||||
charge["chg"] = charge["chg"] / norm_factor
|
|
||||||
|
|
||||||
return asec_charges
|
|
||||||
|
|
||||||
def _calculate_norm_factor(self) -> int:
|
|
||||||
if self.step.dice.nstep[-1] % self.step.dice.isave == 0:
|
|
||||||
nconfigs = round(self.step.dice.nstep[-1] / self.step.dice.isave)
|
|
||||||
else:
|
|
||||||
nconfigs = int(self.step.dice.nstep[-1] / self.step.dice.isave)
|
|
||||||
|
|
||||||
return nconfigs * self.step.nprocs
|
|
||||||
|
|
||||||
def _calculate_total_number_of_sites(self, nsitesref) -> int:
|
|
||||||
nsites_total = self.step.dice.nmol[0] * nsitesref
|
|
||||||
for i in range(1, len(self.step.dice.nmol)):
|
|
||||||
nsites_total += self.step.dice.nmol[i] * len(self.system.molecule[i].atom)
|
|
||||||
|
|
||||||
return nsites_total
|
|
||||||
|
|
||||||
def _read_charges_from_last_step(self, cycle: int, proc: int) -> list[str]:
|
|
||||||
last_xyz_file_path = Path(
|
|
||||||
self.step.simulation_dir, f"step{cycle:02d}", f"p{proc:02d}", "last.xyz"
|
|
||||||
)
|
|
||||||
if not last_xyz_file_path.exists():
|
|
||||||
raise FileNotFoundError(f"File {last_xyz_file_path} does not exist.")
|
|
||||||
|
|
||||||
with open(last_xyz_file_path, "r") as last_xyz_file:
|
|
||||||
lines = last_xyz_file.readlines()
|
|
||||||
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def _evaluate_proc_charges(
|
|
||||||
self, total_nsites: int, proc_charges: list[list[str]]
|
|
||||||
) -> Tuple[List[Dict[str, float | Any]], List[float], List[int]]:
|
|
||||||
asec_charges = []
|
|
||||||
|
|
||||||
thickness = []
|
|
||||||
picked_mols = []
|
|
||||||
|
|
||||||
for charges in proc_charges:
|
|
||||||
charges_nsites = int(charges.pop(0))
|
|
||||||
if int(charges_nsites) != total_nsites:
|
|
||||||
raise ValueError(
|
|
||||||
f"Number of sites does not match total number of sites."
|
|
||||||
)
|
|
||||||
|
|
||||||
thickness.append(self._calculate_proc_thickness(charges))
|
|
||||||
nsites_ref_mol = len(self.system.molecule[0].atom)
|
|
||||||
charges = charges[nsites_ref_mol:]
|
|
||||||
|
|
||||||
mol_count = 0
|
|
||||||
for type in range(len(self.step.dice.nmol)):
|
|
||||||
if type == 0:
|
|
||||||
# Reference Molecule must be ignored from type 0
|
|
||||||
nmols = self.step.dice.nmol[type] - 1
|
|
||||||
else:
|
|
||||||
nmols = self.step.dice.nmol[type]
|
|
||||||
|
|
||||||
for mol in range(nmols):
|
|
||||||
new_molecule = Molecule("ASEC TMP MOLECULE")
|
|
||||||
for site in range(len(self.system.molecule[type].atom)):
|
|
||||||
line = charges.pop(0).split()
|
|
||||||
|
|
||||||
if (
|
|
||||||
line[0].title()
|
|
||||||
!= atomsymb[
|
|
||||||
self.system.molecule[type].atom[site].na
|
|
||||||
].strip()
|
|
||||||
):
|
|
||||||
raise SyntaxError(
|
|
||||||
f"Error: Invalid Dice Output. Atom type does not match."
|
|
||||||
)
|
|
||||||
|
|
||||||
new_molecule.add_atom(
|
|
||||||
Atom(
|
|
||||||
self.system.molecule[type].atom[site].lbl,
|
|
||||||
self.system.molecule[type].atom[site].na,
|
|
||||||
float(line[1]),
|
|
||||||
float(line[2]),
|
|
||||||
float(line[3]),
|
|
||||||
self.system.molecule[type].atom[site].chg,
|
|
||||||
self.system.molecule[type].atom[site].eps,
|
|
||||||
self.system.molecule[type].atom[site].sig,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
distance = self.system.molecule[0].minimum_distance(new_molecule)
|
|
||||||
|
|
||||||
if distance < thickness[-1]:
|
|
||||||
for atom in new_molecule.atom:
|
|
||||||
asec_charges.append(
|
|
||||||
{
|
|
||||||
"lbl": atomsymb[atom.na],
|
|
||||||
"rx": atom.rx,
|
|
||||||
"ry": atom.ry,
|
|
||||||
"rz": atom.rz,
|
|
||||||
"chg": atom.chg,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
mol_count += 1
|
|
||||||
|
|
||||||
picked_mols.append(mol_count)
|
|
||||||
|
|
||||||
return asec_charges, thickness, picked_mols
|
|
||||||
|
|
||||||
def _calculate_proc_thickness(self, charges: list[str]) -> float:
|
|
||||||
box = charges.pop(0).split()[-3:]
|
|
||||||
box = [float(box[0]), float(box[1]), float(box[2])]
|
|
||||||
sizes = self.system.molecule[0].sizes_of_molecule()
|
|
||||||
|
|
||||||
return min(
|
|
||||||
[
|
|
||||||
(box[0] - sizes[0]) / 2,
|
|
||||||
(box[1] - sizes[1]) / 2,
|
|
||||||
(box[2] - sizes[2]) / 2,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
def _make_gaussian_input_file(self, cycle: int, asec_charges: list[dict]) -> None:
|
|
||||||
gaussian_input_file_path = Path(
|
|
||||||
self.step.simulation_dir, f"step{cycle:02d}", "qm", f"asec.gjf"
|
|
||||||
)
|
|
||||||
|
|
||||||
with open(gaussian_input_file_path, "w") as gaussian_input_file:
|
|
||||||
gaussian_input_file.writelines(
|
|
||||||
self._generate_gaussian_input(cycle, asec_charges)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _generate_gaussian_input(
|
|
||||||
self, cycle: int, asec_charges: list[dict]
|
|
||||||
) -> list[str]:
|
|
||||||
gaussian_input = ["%Chk=asec.chk\n"]
|
|
||||||
|
|
||||||
if self.step.mem is not None:
|
|
||||||
gaussian_input.append(f"%Mem={self.step.mem}GB\n")
|
|
||||||
|
|
||||||
gaussian_input.append(f"%Nprocs={self.step.nprocs * self.step.ncores}\n")
|
|
||||||
|
|
||||||
kwords_line = f"#P {self.step.gaussian.level}"
|
|
||||||
|
|
||||||
if self.step.gaussian.keywords:
|
|
||||||
kwords_line += " " + self.step.gaussian.keywords
|
|
||||||
|
|
||||||
if self.step.opt == "yes":
|
|
||||||
kwords_line += " Force"
|
|
||||||
|
|
||||||
kwords_line += " NoSymm"
|
|
||||||
kwords_line += f" Pop={self.step.gaussian.pop} Density=Current"
|
|
||||||
|
|
||||||
if cycle > 1:
|
|
||||||
kwords_line += " Guess=Read"
|
|
||||||
|
|
||||||
gaussian_input.append(textwrap.fill(kwords_line, 90))
|
|
||||||
gaussian_input.append("\n")
|
|
||||||
|
|
||||||
gaussian_input.append("\nForce calculation - Cycle number {}\n".format(cycle))
|
|
||||||
gaussian_input.append("\n")
|
|
||||||
gaussian_input.append(
|
|
||||||
f"{self.step.gaussian.chgmult[0]},{self.step.gaussian.chgmult[1]}\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
for atom in self.system.molecule[0].atom:
|
|
||||||
symbol = atomsymb[atom.na]
|
|
||||||
gaussian_input.append(
|
|
||||||
"{:<2s} {:>10.5f} {:>10.5f} {:>10.5f}\n".format(
|
|
||||||
symbol, atom.rx, atom.ry, atom.rz
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
gaussian_input.append("\n")
|
|
||||||
|
|
||||||
for charge in asec_charges:
|
|
||||||
gaussian_input.append(
|
|
||||||
"{:>10.5f} {:>10.5f} {:>10.5f} {:>11.8f}\n".format(
|
|
||||||
charge["rx"], charge["ry"], charge["rz"], charge["chg"]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
gaussian_input.append("\n")
|
|
||||||
|
|
||||||
return gaussian_input
|
|
||||||
|
|
||||||
def _run_gaussian(self, cycle: int) -> None:
|
|
||||||
qm_dir = Path(self.step.simulation_dir, f"step{(cycle):02d}", "qm")
|
|
||||||
|
|
||||||
working_dir = os.getcwd()
|
|
||||||
os.chdir(qm_dir)
|
|
||||||
|
|
||||||
infile = "asec.gjf"
|
|
||||||
|
|
||||||
operation = None
|
|
||||||
if self.step.opt:
|
|
||||||
operation = "forces"
|
|
||||||
else:
|
|
||||||
operation = "charges"
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
f"Calculation of {operation} initiated with Gaussian on {date_time()}\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
if shutil.which("bash") is not None:
|
|
||||||
exit_status = subprocess.call(
|
|
||||||
[
|
|
||||||
"bash",
|
|
||||||
"-c",
|
|
||||||
"exec -a {}-step{} {} {}".format(
|
|
||||||
self.step.gaussian.qmprog,
|
|
||||||
cycle,
|
|
||||||
self.step.gaussian.qmprog,
|
|
||||||
infile,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
exit_status = subprocess.call([self.step.gaussian.qmprog, infile])
|
|
||||||
|
|
||||||
if exit_status != 0:
|
|
||||||
raise SystemError("Gaussian process did not exit properly")
|
|
||||||
|
|
||||||
logger.info(f"Calculation of {operation} finished on {date_time()}")
|
|
||||||
|
|
||||||
os.chdir(working_dir)
|
|
||||||
|
|
||||||
def _run_formchk(self, cycle: int):
|
|
||||||
qm_dir = Path(self.step.simulation_dir, f"step{(cycle):02d}", "qm")
|
|
||||||
|
|
||||||
work_dir = os.getcwd()
|
|
||||||
os.chdir(qm_dir)
|
|
||||||
|
|
||||||
logger.info("Formatting the checkpoint file... \n")
|
|
||||||
|
|
||||||
exit_status = subprocess.call(
|
|
||||||
["formchk", "asec.chk"], stdout=subprocess.DEVNULL
|
|
||||||
)
|
|
||||||
|
|
||||||
if exit_status != 0:
|
|
||||||
raise SystemError("Formchk process did not exit properly")
|
|
||||||
|
|
||||||
logger.info("Done\n")
|
|
||||||
|
|
||||||
os.chdir(work_dir)
|
|
||||||
|
|
||||||
def _read_charges_from_fchk(self, cycle: int):
|
|
||||||
fchk_file_path = Path("simfiles", f"step{cycle:02d}", "qm", "asec.fchk")
|
|
||||||
with open(fchk_file_path) as fchk:
|
|
||||||
fchkfile = fchk.readlines()
|
|
||||||
|
|
||||||
if self.step.gaussian.pop in ["chelpg", "mk"]:
|
|
||||||
CHARGE_FLAG = "ESP Charges"
|
|
||||||
else:
|
|
||||||
CHARGE_FLAG = "ESP Charges"
|
|
||||||
|
|
||||||
start = fchkfile.pop(0).strip()
|
|
||||||
while start.find(CHARGE_FLAG) != 0: # expression in begining of line
|
|
||||||
start = fchkfile.pop(0).strip()
|
|
||||||
|
|
||||||
charges: List[float] = []
|
|
||||||
while len(charges) < len(self.system.molecule[0].atom):
|
|
||||||
charges.extend([float(x) for x in fchkfile.pop(0).split()])
|
|
||||||
|
|
||||||
return charges
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
from typing import Protocol, runtime_checkable
|
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
|
||||||
class Dataclass(Protocol):
|
|
||||||
__dataclass_fields__: dict
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
import logging
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
def valid_logger(func):
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
logger = args[0]
|
|
||||||
assert logger._was_set, "Logger is not set. Please call set_logger() first."
|
|
||||||
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
class Logger:
|
|
||||||
outfile = None
|
|
||||||
|
|
||||||
_logger = None
|
|
||||||
|
|
||||||
_was_set = False
|
|
||||||
|
|
||||||
def __init__(self, logger_name):
|
|
||||||
if self._logger is None:
|
|
||||||
self._logger = logging.getLogger(logger_name)
|
|
||||||
|
|
||||||
def set_logger(self, outfile="run.log", level=logging.INFO, stream=None):
|
|
||||||
outfile_path = None
|
|
||||||
if outfile is not None and stream is None:
|
|
||||||
outfile_path = Path(outfile)
|
|
||||||
if outfile_path.exists():
|
|
||||||
outfile_path.rename(str(outfile_path) + ".backup")
|
|
||||||
|
|
||||||
if level is not None:
|
|
||||||
self._logger.setLevel(level)
|
|
||||||
|
|
||||||
self._create_handlers(outfile_path, stream)
|
|
||||||
|
|
||||||
self._was_set = True
|
|
||||||
|
|
||||||
@valid_logger
|
|
||||||
def info(self, message):
|
|
||||||
self._logger.info(message)
|
|
||||||
|
|
||||||
@valid_logger
|
|
||||||
def debug(self, message):
|
|
||||||
self._logger.debug(message)
|
|
||||||
|
|
||||||
@valid_logger
|
|
||||||
def warning(self, message):
|
|
||||||
self._logger.warning(message)
|
|
||||||
|
|
||||||
@valid_logger
|
|
||||||
def error(self, message):
|
|
||||||
self._logger.error(message)
|
|
||||||
|
|
||||||
def _create_handlers(self, outfile_path: Path, stream):
|
|
||||||
handlers = []
|
|
||||||
if outfile_path is not None:
|
|
||||||
handlers.append(logging.FileHandler(outfile_path, mode="a+"))
|
|
||||||
elif stream is not None:
|
|
||||||
handlers.append(logging.StreamHandler(stream))
|
|
||||||
else:
|
|
||||||
handlers.append(logging.StreamHandler())
|
|
||||||
|
|
||||||
for handler in handlers:
|
|
||||||
handler.setFormatter(logging.Formatter("%(message)s"))
|
|
||||||
self._logger.addHandler(handler)
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
for handler in self._logger.handlers:
|
|
||||||
handler.close()
|
|
||||||
self._logger.removeHandler(handler)
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
#### Label used in Dice for a ghost atom
|
|
||||||
dice_ghost_label = "Xx"
|
|
||||||
|
|
||||||
#### Tuple of atom symbols
|
|
||||||
atomsymb = (
|
|
||||||
"00",
|
|
||||||
"H ",
|
|
||||||
"He",
|
|
||||||
"Li",
|
|
||||||
"Be",
|
|
||||||
"B ",
|
|
||||||
"C ",
|
|
||||||
"N ",
|
|
||||||
"O ",
|
|
||||||
"F ",
|
|
||||||
"Ne",
|
|
||||||
"Na",
|
|
||||||
"Mg",
|
|
||||||
"Al",
|
|
||||||
"Si",
|
|
||||||
"P ",
|
|
||||||
"S ",
|
|
||||||
"Cl",
|
|
||||||
"Ar",
|
|
||||||
"K ",
|
|
||||||
"Ca",
|
|
||||||
"Sc",
|
|
||||||
"Ti",
|
|
||||||
"V ",
|
|
||||||
"Cr",
|
|
||||||
"Mn",
|
|
||||||
"Fe",
|
|
||||||
"Co",
|
|
||||||
"Ni",
|
|
||||||
"Cu",
|
|
||||||
"Zn",
|
|
||||||
"Ga",
|
|
||||||
"Ge",
|
|
||||||
"As",
|
|
||||||
"Se",
|
|
||||||
"Br",
|
|
||||||
"Kr",
|
|
||||||
"Rb",
|
|
||||||
"Sr",
|
|
||||||
"Y ",
|
|
||||||
"Zr",
|
|
||||||
"Nb",
|
|
||||||
"Mo",
|
|
||||||
"Tc",
|
|
||||||
"Ru",
|
|
||||||
"Rh",
|
|
||||||
"Pd",
|
|
||||||
"Ag",
|
|
||||||
"Cd",
|
|
||||||
"In",
|
|
||||||
"Sn",
|
|
||||||
"Sb",
|
|
||||||
"Te",
|
|
||||||
"I ",
|
|
||||||
"Xe",
|
|
||||||
"Cs",
|
|
||||||
"Ba",
|
|
||||||
"La",
|
|
||||||
"Ce",
|
|
||||||
"Pr",
|
|
||||||
"Nd",
|
|
||||||
"Pm",
|
|
||||||
"Sm",
|
|
||||||
"Eu",
|
|
||||||
"Gd",
|
|
||||||
"Tb",
|
|
||||||
"Dy",
|
|
||||||
"Ho",
|
|
||||||
"Er",
|
|
||||||
"Tm",
|
|
||||||
"Yb",
|
|
||||||
"Lu",
|
|
||||||
"Hf",
|
|
||||||
"Ta",
|
|
||||||
"W ",
|
|
||||||
"Re",
|
|
||||||
"Os",
|
|
||||||
"Ir",
|
|
||||||
"Pt",
|
|
||||||
"Au",
|
|
||||||
"Hg",
|
|
||||||
"Ti",
|
|
||||||
"Pb",
|
|
||||||
"Bi",
|
|
||||||
"Po",
|
|
||||||
"At",
|
|
||||||
"Rn",
|
|
||||||
"Fr",
|
|
||||||
"Ra",
|
|
||||||
"Ac",
|
|
||||||
"Th",
|
|
||||||
"Pa",
|
|
||||||
"U ",
|
|
||||||
"Np",
|
|
||||||
"Pu",
|
|
||||||
"Am",
|
|
||||||
"Cm",
|
|
||||||
"Bk",
|
|
||||||
"Cf",
|
|
||||||
"Es",
|
|
||||||
"Fm",
|
|
||||||
"Md",
|
|
||||||
"No",
|
|
||||||
"Lr",
|
|
||||||
dice_ghost_label,
|
|
||||||
)
|
|
||||||
|
|
||||||
#### Tuple of atom masses
|
|
||||||
atommass = (
|
|
||||||
0.0,
|
|
||||||
1.0079,
|
|
||||||
4.0026,
|
|
||||||
6.9410,
|
|
||||||
9.0122,
|
|
||||||
10.811,
|
|
||||||
12.011,
|
|
||||||
14.007,
|
|
||||||
15.999,
|
|
||||||
18.998,
|
|
||||||
20.180,
|
|
||||||
22.990,
|
|
||||||
24.305,
|
|
||||||
26.982,
|
|
||||||
28.086,
|
|
||||||
30.974,
|
|
||||||
32.065,
|
|
||||||
35.453,
|
|
||||||
39.948,
|
|
||||||
39.098,
|
|
||||||
40.078,
|
|
||||||
44.956,
|
|
||||||
47.867,
|
|
||||||
50.942,
|
|
||||||
51.996,
|
|
||||||
54.938,
|
|
||||||
55.845,
|
|
||||||
58.933,
|
|
||||||
58.693,
|
|
||||||
63.546,
|
|
||||||
65.409,
|
|
||||||
69.723,
|
|
||||||
72.640,
|
|
||||||
74.922,
|
|
||||||
78.960,
|
|
||||||
79.904,
|
|
||||||
83.798,
|
|
||||||
85.468,
|
|
||||||
87.620,
|
|
||||||
88.906,
|
|
||||||
91.224,
|
|
||||||
92.906,
|
|
||||||
95.940,
|
|
||||||
98.000,
|
|
||||||
101.07,
|
|
||||||
102.91,
|
|
||||||
106.42,
|
|
||||||
107.87,
|
|
||||||
112.41,
|
|
||||||
114.82,
|
|
||||||
118.71,
|
|
||||||
121.76,
|
|
||||||
127.60,
|
|
||||||
126.90,
|
|
||||||
131.29,
|
|
||||||
132.91,
|
|
||||||
137.33,
|
|
||||||
138.91,
|
|
||||||
140.12,
|
|
||||||
140.91,
|
|
||||||
144.24,
|
|
||||||
145.00,
|
|
||||||
150.36,
|
|
||||||
151.96,
|
|
||||||
157.25,
|
|
||||||
158.93,
|
|
||||||
162.50,
|
|
||||||
164.93,
|
|
||||||
167.26,
|
|
||||||
168.93,
|
|
||||||
173.04,
|
|
||||||
174.97,
|
|
||||||
178.49,
|
|
||||||
180.95,
|
|
||||||
183.84,
|
|
||||||
186.21,
|
|
||||||
190.23,
|
|
||||||
192.22,
|
|
||||||
195.08,
|
|
||||||
196.97,
|
|
||||||
200.59,
|
|
||||||
204.38,
|
|
||||||
207.20,
|
|
||||||
208.98,
|
|
||||||
209.00,
|
|
||||||
210.00,
|
|
||||||
222.00,
|
|
||||||
223.00,
|
|
||||||
226.00,
|
|
||||||
227.00,
|
|
||||||
232.04,
|
|
||||||
231.04,
|
|
||||||
238.03,
|
|
||||||
237.00,
|
|
||||||
244.00,
|
|
||||||
243.00,
|
|
||||||
247.00,
|
|
||||||
247.00,
|
|
||||||
251.00,
|
|
||||||
252.00,
|
|
||||||
257.00,
|
|
||||||
258.00,
|
|
||||||
259.00,
|
|
||||||
262.00,
|
|
||||||
0.000,
|
|
||||||
)
|
|
||||||
|
|
||||||
#### Number of the ghost atom
|
|
||||||
ghost_number = len(atomsymb) - 1
|
|
||||||
37
diceplayer/state/state_handler.py
Normal file
37
diceplayer/state/state_handler.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.logger import logger
|
||||||
|
from diceplayer.state.state_model import StateModel
|
||||||
|
|
||||||
|
import pickle
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class StateHandler:
|
||||||
|
def __init__(self, sim_dir: Path, state_file: str = "state.pkl"):
|
||||||
|
if not sim_dir.exists():
|
||||||
|
sim_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
self._state_file = sim_dir / state_file
|
||||||
|
|
||||||
|
def get(self, config: PlayerConfig, force=False) -> StateModel | None:
|
||||||
|
if not self._state_file.exists():
|
||||||
|
return None
|
||||||
|
|
||||||
|
with open(self._state_file, mode="rb") as file:
|
||||||
|
data = pickle.load(file)
|
||||||
|
model = StateModel.model_validate(data)
|
||||||
|
|
||||||
|
if config != model.config and not force:
|
||||||
|
logger.warning(
|
||||||
|
"The configuration in the state file does not match the provided configuration."
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
return model
|
||||||
|
|
||||||
|
def save(self, state: StateModel) -> None:
|
||||||
|
with self._state_file.open(mode="wb") as f:
|
||||||
|
pickle.dump(state.model_dump(), f)
|
||||||
|
|
||||||
|
def delete(self) -> None:
|
||||||
|
if self._state_file.exists():
|
||||||
|
self._state_file.unlink()
|
||||||
19
diceplayer/state/state_model.py
Normal file
19
diceplayer/state/state_model.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.environment import System
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
|
|
||||||
|
class StateModel(BaseModel):
|
||||||
|
config: PlayerConfig
|
||||||
|
system: System
|
||||||
|
current_cycle: int = 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_config(cls, config: PlayerConfig) -> Self:
|
||||||
|
return cls(
|
||||||
|
config=config,
|
||||||
|
system=System(),
|
||||||
|
current_cycle=0,
|
||||||
|
)
|
||||||
21
diceplayer/utils/__init__.py
Normal file
21
diceplayer/utils/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from .logger import RunLogger
|
||||||
|
from .misc import (
|
||||||
|
compress_files_1mb,
|
||||||
|
date_time,
|
||||||
|
make_qm_dir,
|
||||||
|
make_step_dir,
|
||||||
|
weekday_date_time,
|
||||||
|
)
|
||||||
|
from .ptable import AtomInfo, PTable
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"RunLogger",
|
||||||
|
"PTable",
|
||||||
|
"AtomInfo",
|
||||||
|
"weekday_date_time",
|
||||||
|
"date_time",
|
||||||
|
"compress_files_1mb",
|
||||||
|
"make_step_dir",
|
||||||
|
"make_qm_dir",
|
||||||
|
]
|
||||||
29
diceplayer/utils/cache.py
Normal file
29
diceplayer/utils/cache.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
def invalidate_computed_properties():
|
||||||
|
"""
|
||||||
|
Decorator function to invalidate the cached properties of the molecule when a new atom is added
|
||||||
|
|
||||||
|
Args:
|
||||||
|
properties (list[str]): list of the names of the properties to be invalidated
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_cached_properies(cls: type) -> set[str]:
|
||||||
|
return {
|
||||||
|
name
|
||||||
|
for name, value in cls.__dict__.items()
|
||||||
|
if isinstance(value, cached_property)
|
||||||
|
}
|
||||||
|
|
||||||
|
def decorator(func):
|
||||||
|
def wrapper(self, *args, **kwargs):
|
||||||
|
result = func(self, *args, **kwargs)
|
||||||
|
for prop in get_cached_properies(self.__class__):
|
||||||
|
if hasattr(self, prop):
|
||||||
|
delattr(self, prop)
|
||||||
|
return result
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return decorator
|
||||||
44
diceplayer/utils/logger.py
Normal file
44
diceplayer/utils/logger.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
from typing_extensions import TypeVar
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
H = TypeVar("H", bound=logging.Handler)
|
||||||
|
|
||||||
|
|
||||||
|
class RunLogger(logging.Logger):
|
||||||
|
def __init__(self, name, level=logging.INFO, stream=sys.stdout):
|
||||||
|
super().__init__(name, level)
|
||||||
|
|
||||||
|
self.handlers.clear()
|
||||||
|
|
||||||
|
self.handlers.append(
|
||||||
|
self._configure_handler(logging.StreamHandler(stream), level)
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_output_file(self, outfile: Path, level=logging.INFO):
|
||||||
|
for handler in list(self.handlers):
|
||||||
|
if not isinstance(handler, logging.FileHandler):
|
||||||
|
continue
|
||||||
|
self.handlers.remove(handler)
|
||||||
|
|
||||||
|
self.handlers.append(self._create_file_handler(outfile, level))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _create_file_handler(file: str | Path, level) -> logging.FileHandler:
|
||||||
|
file = Path(file)
|
||||||
|
|
||||||
|
if file.exists():
|
||||||
|
file.rename(file.with_suffix(".log.backup"))
|
||||||
|
|
||||||
|
handler = logging.FileHandler(file)
|
||||||
|
return RunLogger._configure_handler(handler, level)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _configure_handler(handler: H, level) -> H:
|
||||||
|
handler.setLevel(level)
|
||||||
|
formatter = logging.Formatter("%(message)s")
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
return handler
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
from typing_extensions import Final
|
||||||
|
|
||||||
import gzip
|
import gzip
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from typing import Final
|
|
||||||
|
|
||||||
####################################### constants ######################################
|
####################################### constants ######################################
|
||||||
|
|
||||||
@@ -11,6 +13,8 @@ from typing import Final
|
|||||||
BOHR2ANG: Final[float] = 0.52917721092
|
BOHR2ANG: Final[float] = 0.52917721092
|
||||||
ANG2BOHR: Final[float] = 1 / BOHR2ANG
|
ANG2BOHR: Final[float] = 1 / BOHR2ANG
|
||||||
|
|
||||||
|
EA_2_DEBYE = 1 / 0.20819434
|
||||||
|
|
||||||
|
|
||||||
####################################### functions ######################################
|
####################################### functions ######################################
|
||||||
|
|
||||||
@@ -35,7 +39,7 @@ def compress_files_1mb(path):
|
|||||||
with open(file, "rb") as f_in:
|
with open(file, "rb") as f_in:
|
||||||
with gzip.open(filegz, "wb") as f_out:
|
with gzip.open(filegz, "wb") as f_out:
|
||||||
shutil.copyfileobj(f_in, f_out)
|
shutil.copyfileobj(f_in, f_out)
|
||||||
except:
|
except Exception as _:
|
||||||
sys.exit("Error: cannot compress file {}".format(file))
|
sys.exit("Error: cannot compress file {}".format(file))
|
||||||
|
|
||||||
os.chdir(working_dir)
|
os.chdir(working_dir)
|
||||||
@@ -51,7 +55,7 @@ def make_step_dir(cycle):
|
|||||||
sys.exit("Error: a file or directory {} already exists".format(step_dir))
|
sys.exit("Error: a file or directory {} already exists".format(step_dir))
|
||||||
try:
|
try:
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except:
|
except Exception as _:
|
||||||
sys.exit("Error: cannot make directory {}".format(step_dir))
|
sys.exit("Error: cannot make directory {}".format(step_dir))
|
||||||
|
|
||||||
|
|
||||||
@@ -61,5 +65,5 @@ def make_qm_dir(cycle):
|
|||||||
path = sim_dir + os.sep + step_dir + os.sep + "qm"
|
path = sim_dir + os.sep + step_dir + os.sep + "qm"
|
||||||
try:
|
try:
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except:
|
except Exception as _:
|
||||||
sys.exit("Error: cannot make directory {}".format(path))
|
sys.exit("Error: cannot make directory {}".format(path))
|
||||||
55
diceplayer/utils/potential.py
Normal file
55
diceplayer/utils/potential.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.environment import Atom, Molecule, System
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def read_system_from_phb(config: PlayerConfig) -> System:
|
||||||
|
phb_file = Path(config.dice.ljname)
|
||||||
|
if not phb_file.exists():
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
ljc_data = phb_file.read_text(encoding="utf-8").splitlines()
|
||||||
|
|
||||||
|
combrule = ljc_data.pop(0).strip()
|
||||||
|
if combrule != config.dice.combrule:
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid combrule defined in {phb_file}. Expected the same value configured in the config file"
|
||||||
|
)
|
||||||
|
|
||||||
|
ntypes = ljc_data.pop(0).strip()
|
||||||
|
if not ntypes.isdigit():
|
||||||
|
raise ValueError(f"Invalid ntypes defined in {phb_file}")
|
||||||
|
|
||||||
|
nmol = int(ntypes)
|
||||||
|
if nmol != len(config.dice.nmol):
|
||||||
|
raise ValueError(f"Invalid nmol defined in {phb_file}")
|
||||||
|
|
||||||
|
sys = System()
|
||||||
|
|
||||||
|
for i in range(nmol):
|
||||||
|
nsites, molname = ljc_data.pop(0).split()
|
||||||
|
|
||||||
|
if not nsites.isdigit():
|
||||||
|
raise ValueError(f"Invalid nsites defined in {phb_file}")
|
||||||
|
nsites = int(nsites)
|
||||||
|
|
||||||
|
mol = Molecule(molname)
|
||||||
|
|
||||||
|
for j in range(nsites):
|
||||||
|
_fields = ljc_data.pop(0).split()
|
||||||
|
mol.add_atom(Atom(*_fields))
|
||||||
|
|
||||||
|
sys.add_type(mol)
|
||||||
|
|
||||||
|
return sys
|
||||||
|
|
||||||
|
|
||||||
|
# def write_phb(phb_file: Path, state: StateModel) -> None:
|
||||||
|
# if phb_file.exists():
|
||||||
|
# raise RuntimeError(f"File {phb_file} already exists")
|
||||||
|
#
|
||||||
|
# with open(phb_file, "w") as f:
|
||||||
|
# f.write(f"{state.config.dice.combrule}\n")
|
||||||
|
# f.write(f"{len(state.system.nmols)}\n")
|
||||||
|
# f.write(f"{state.config.dice.nmol}\n")
|
||||||
143
diceplayer/utils/ptable.py
Normal file
143
diceplayer/utils/ptable.py
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
DICE_GHOST_LABEL = "Xx"
|
||||||
|
|
||||||
|
#### Number of the ghost atom
|
||||||
|
GHOST_NUMBER = 0
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class AtomInfo:
|
||||||
|
atomic_number: int
|
||||||
|
symbol: str
|
||||||
|
mass: float
|
||||||
|
|
||||||
|
|
||||||
|
class PTable(Enum):
|
||||||
|
Xx = AtomInfo(GHOST_NUMBER, DICE_GHOST_LABEL, 0.0)
|
||||||
|
H = AtomInfo(1, "H", 1.0079)
|
||||||
|
He = AtomInfo(2, "He", 4.0026)
|
||||||
|
Li = AtomInfo(3, "Li", 6.9410)
|
||||||
|
Be = AtomInfo(4, "Be", 9.0122)
|
||||||
|
B = AtomInfo(5, "B", 10.811)
|
||||||
|
C = AtomInfo(6, "C", 12.011)
|
||||||
|
N = AtomInfo(7, "N", 14.007)
|
||||||
|
O = AtomInfo(8, "O", 15.999)
|
||||||
|
F = AtomInfo(9, "F", 18.998)
|
||||||
|
Ne = AtomInfo(10, "Ne", 20.180)
|
||||||
|
Na = AtomInfo(11, "Na", 22.990)
|
||||||
|
Mg = AtomInfo(12, "Mg", 24.305)
|
||||||
|
Al = AtomInfo(13, "Al", 26.982)
|
||||||
|
Si = AtomInfo(14, "Si", 28.086)
|
||||||
|
P = AtomInfo(15, "P", 30.974)
|
||||||
|
S = AtomInfo(16, "S", 32.065)
|
||||||
|
Cl = AtomInfo(17, "Cl", 35.453)
|
||||||
|
Ar = AtomInfo(18, "Ar", 39.948)
|
||||||
|
K = AtomInfo(19, "K", 39.098)
|
||||||
|
Ca = AtomInfo(20, "Ca", 40.078)
|
||||||
|
Sc = AtomInfo(21, "Sc", 44.956)
|
||||||
|
Ti = AtomInfo(22, "Ti", 47.867)
|
||||||
|
V = AtomInfo(23, "V", 50.942)
|
||||||
|
Cr = AtomInfo(24, "Cr", 51.996)
|
||||||
|
Mn = AtomInfo(25, "Mn", 54.938)
|
||||||
|
Fe = AtomInfo(26, "Fe", 55.845)
|
||||||
|
Co = AtomInfo(27, "Co", 58.933)
|
||||||
|
Ni = AtomInfo(28, "Ni", 58.693)
|
||||||
|
Cu = AtomInfo(29, "Cu", 63.546)
|
||||||
|
Zn = AtomInfo(30, "Zn", 65.409)
|
||||||
|
Ga = AtomInfo(31, "Ga", 69.723)
|
||||||
|
Ge = AtomInfo(32, "Ge", 72.640)
|
||||||
|
As = AtomInfo(33, "As", 74.922)
|
||||||
|
Se = AtomInfo(34, "Se", 78.960)
|
||||||
|
Br = AtomInfo(35, "Br", 79.904)
|
||||||
|
Kr = AtomInfo(36, "Kr", 83.798)
|
||||||
|
Rb = AtomInfo(37, "Rb", 85.468)
|
||||||
|
Sr = AtomInfo(38, "Sr", 87.620)
|
||||||
|
Y = AtomInfo(39, "Y", 88.906)
|
||||||
|
Zr = AtomInfo(40, "Zr", 91.224)
|
||||||
|
Nb = AtomInfo(41, "Nb", 92.906)
|
||||||
|
Mo = AtomInfo(42, "Mo", 95.940)
|
||||||
|
Tc = AtomInfo(43, "Tc", 98.000)
|
||||||
|
Ru = AtomInfo(44, "Ru", 101.07)
|
||||||
|
Rh = AtomInfo(45, "Rh", 102.91)
|
||||||
|
Pd = AtomInfo(46, "Pd", 106.42)
|
||||||
|
Ag = AtomInfo(47, "Ag", 107.87)
|
||||||
|
Cd = AtomInfo(48, "Cd", 112.41)
|
||||||
|
In = AtomInfo(49, "In", 114.82)
|
||||||
|
Sn = AtomInfo(50, "Sn", 118.71)
|
||||||
|
Sb = AtomInfo(51, "Sb", 121.76)
|
||||||
|
Te = AtomInfo(52, "Te", 127.60)
|
||||||
|
I = AtomInfo(53, "I", 126.90)
|
||||||
|
Xe = AtomInfo(54, "Xe", 131.29)
|
||||||
|
Cs = AtomInfo(55, "Cs", 132.91)
|
||||||
|
Ba = AtomInfo(56, "Ba", 137.33)
|
||||||
|
La = AtomInfo(57, "La", 138.91)
|
||||||
|
Ce = AtomInfo(58, "Ce", 140.12)
|
||||||
|
Pr = AtomInfo(59, "Pr", 140.91)
|
||||||
|
Nd = AtomInfo(60, "Nd", 144.24)
|
||||||
|
Pm = AtomInfo(61, "Pm", 145.00)
|
||||||
|
Sm = AtomInfo(62, "Sm", 150.36)
|
||||||
|
Eu = AtomInfo(63, "Eu", 151.96)
|
||||||
|
Gd = AtomInfo(64, "Gd", 157.25)
|
||||||
|
Tb = AtomInfo(65, "Tb", 158.93)
|
||||||
|
Dy = AtomInfo(66, "Dy", 162.50)
|
||||||
|
Ho = AtomInfo(67, "Ho", 164.93)
|
||||||
|
Er = AtomInfo(68, "Er", 167.26)
|
||||||
|
Tm = AtomInfo(69, "Tm", 168.93)
|
||||||
|
Yb = AtomInfo(70, "Yb", 173.04)
|
||||||
|
Lu = AtomInfo(71, "Lu", 174.97)
|
||||||
|
Hf = AtomInfo(72, "Hf", 178.49)
|
||||||
|
Ta = AtomInfo(73, "Ta", 180.95)
|
||||||
|
W = AtomInfo(74, "W", 183.84)
|
||||||
|
Re = AtomInfo(75, "Re", 186.21)
|
||||||
|
Os = AtomInfo(76, "Os", 190.23)
|
||||||
|
Ir = AtomInfo(77, "Ir", 192.22)
|
||||||
|
Pt = AtomInfo(78, "Pt", 195.08)
|
||||||
|
Au = AtomInfo(79, "Au", 196.97)
|
||||||
|
Hg = AtomInfo(80, "Hg", 200.59)
|
||||||
|
Tl = AtomInfo(81, "Tl", 204.38)
|
||||||
|
Pb = AtomInfo(82, "Pb", 207.20)
|
||||||
|
Bi = AtomInfo(83, "Bi", 208.98)
|
||||||
|
Po = AtomInfo(84, "Po", 209.00)
|
||||||
|
At = AtomInfo(85, "At", 210.00)
|
||||||
|
Rn = AtomInfo(86, "Rn", 222.00)
|
||||||
|
Fr = AtomInfo(87, "Fr", 223.00)
|
||||||
|
Ra = AtomInfo(88, "Ra", 226.00)
|
||||||
|
Ac = AtomInfo(89, "Ac", 227.00)
|
||||||
|
Th = AtomInfo(90, "Th", 232.04)
|
||||||
|
Pa = AtomInfo(91, "Pa", 231.04)
|
||||||
|
U = AtomInfo(92, "U", 238.03)
|
||||||
|
Np = AtomInfo(93, "Np", 237.00)
|
||||||
|
Pu = AtomInfo(94, "Pu", 244.00)
|
||||||
|
Am = AtomInfo(95, "Am", 243.00)
|
||||||
|
Cm = AtomInfo(96, "Cm", 247.00)
|
||||||
|
Bk = AtomInfo(97, "Bk", 247.00)
|
||||||
|
Cf = AtomInfo(98, "Cf", 251.00)
|
||||||
|
Es = AtomInfo(99, "Es", 252.00)
|
||||||
|
Fm = AtomInfo(100, "Fm", 257.00)
|
||||||
|
Md = AtomInfo(101, "Md", 258.00)
|
||||||
|
No = AtomInfo(102, "No", 259.00)
|
||||||
|
Lr = AtomInfo(103, "Lr", 262.00)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_atomic_symbol(cls, atomic_number: int) -> str:
|
||||||
|
for element in cls:
|
||||||
|
if element.value.atomic_number == atomic_number:
|
||||||
|
return element.value.symbol
|
||||||
|
raise ValueError(f"Atomic number {atomic_number} not found in PTable.")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_atomic_mass(cls, atomic_number: int) -> float:
|
||||||
|
for element in cls:
|
||||||
|
if element.value.atomic_number == atomic_number:
|
||||||
|
return element.value.mass
|
||||||
|
raise ValueError(f"Atomic number {atomic_number} not found in PTable.")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_from_atomic_number(cls, atomic_number: int) -> AtomInfo:
|
||||||
|
for element in cls:
|
||||||
|
if element.value.atomic_number == atomic_number:
|
||||||
|
return element.value
|
||||||
|
raise ValueError(f"Atomic number {atomic_number} not found in PTable.")
|
||||||
594
poetry.lock
generated
594
poetry.lock
generated
@@ -1,594 +0,0 @@
|
|||||||
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "argparse"
|
|
||||||
version = "1.4.0"
|
|
||||||
description = "Python command-line parsing library"
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
files = [
|
|
||||||
{file = "argparse-1.4.0-py2.py3-none-any.whl", hash = "sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314"},
|
|
||||||
{file = "argparse-1.4.0.tar.gz", hash = "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "black"
|
|
||||||
version = "24.4.2"
|
|
||||||
description = "The uncompromising code formatter."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "black-24.4.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dd1b5a14e417189db4c7b64a6540f31730713d173f0b63e55fabd52d61d8fdce"},
|
|
||||||
{file = "black-24.4.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e537d281831ad0e71007dcdcbe50a71470b978c453fa41ce77186bbe0ed6021"},
|
|
||||||
{file = "black-24.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063"},
|
|
||||||
{file = "black-24.4.2-cp310-cp310-win_amd64.whl", hash = "sha256:7768a0dbf16a39aa5e9a3ded568bb545c8c2727396d063bbaf847df05b08cd96"},
|
|
||||||
{file = "black-24.4.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:257d724c2c9b1660f353b36c802ccece186a30accc7742c176d29c146df6e474"},
|
|
||||||
{file = "black-24.4.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bdde6f877a18f24844e381d45e9947a49e97933573ac9d4345399be37621e26c"},
|
|
||||||
{file = "black-24.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e151054aa00bad1f4e1f04919542885f89f5f7d086b8a59e5000e6c616896ffb"},
|
|
||||||
{file = "black-24.4.2-cp311-cp311-win_amd64.whl", hash = "sha256:7e122b1c4fb252fd85df3ca93578732b4749d9be076593076ef4d07a0233c3e1"},
|
|
||||||
{file = "black-24.4.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:accf49e151c8ed2c0cdc528691838afd217c50412534e876a19270fea1e28e2d"},
|
|
||||||
{file = "black-24.4.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:88c57dc656038f1ab9f92b3eb5335ee9b021412feaa46330d5eba4e51fe49b04"},
|
|
||||||
{file = "black-24.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be8bef99eb46d5021bf053114442914baeb3649a89dc5f3a555c88737e5e98fc"},
|
|
||||||
{file = "black-24.4.2-cp312-cp312-win_amd64.whl", hash = "sha256:415e686e87dbbe6f4cd5ef0fbf764af7b89f9057b97c908742b6008cc554b9c0"},
|
|
||||||
{file = "black-24.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bf10f7310db693bb62692609b397e8d67257c55f949abde4c67f9cc574492cc7"},
|
|
||||||
{file = "black-24.4.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:98e123f1d5cfd42f886624d84464f7756f60ff6eab89ae845210631714f6db94"},
|
|
||||||
{file = "black-24.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48a85f2cb5e6799a9ef05347b476cce6c182d6c71ee36925a6c194d074336ef8"},
|
|
||||||
{file = "black-24.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:b1530ae42e9d6d5b670a34db49a94115a64596bc77710b1d05e9801e62ca0a7c"},
|
|
||||||
{file = "black-24.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:37aae07b029fa0174d39daf02748b379399b909652a806e5708199bd93899da1"},
|
|
||||||
{file = "black-24.4.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:da33a1a5e49c4122ccdfd56cd021ff1ebc4a1ec4e2d01594fef9b6f267a9e741"},
|
|
||||||
{file = "black-24.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e"},
|
|
||||||
{file = "black-24.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:b9176b9832e84308818a99a561e90aa479e73c523b3f77afd07913380ae2eab7"},
|
|
||||||
{file = "black-24.4.2-py3-none-any.whl", hash = "sha256:d36ed1124bb81b32f8614555b34cc4259c3fbc7eec17870e8ff8ded335b58d8c"},
|
|
||||||
{file = "black-24.4.2.tar.gz", hash = "sha256:c872b53057f000085da66a19c55d68f6f8ddcac2642392ad3a355878406fbd4d"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
click = ">=8.0.0"
|
|
||||||
mypy-extensions = ">=0.4.3"
|
|
||||||
packaging = ">=22.0"
|
|
||||||
pathspec = ">=0.9.0"
|
|
||||||
platformdirs = ">=2"
|
|
||||||
tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""}
|
|
||||||
typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""}
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
colorama = ["colorama (>=0.4.3)"]
|
|
||||||
d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"]
|
|
||||||
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
|
|
||||||
uvloop = ["uvloop (>=0.15.2)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfgv"
|
|
||||||
version = "3.4.0"
|
|
||||||
description = "Validate configuration and produce human readable error messages."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "cfgv-3.4.0-py2.py3-none-any.whl", hash = "sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9"},
|
|
||||||
{file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "click"
|
|
||||||
version = "8.1.7"
|
|
||||||
description = "Composable command line interface toolkit"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
files = [
|
|
||||||
{file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"},
|
|
||||||
{file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "colorama"
|
|
||||||
version = "0.4.6"
|
|
||||||
description = "Cross-platform colored terminal text."
|
|
||||||
optional = false
|
|
||||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
|
||||||
files = [
|
|
||||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
|
||||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "coverage"
|
|
||||||
version = "7.6.0"
|
|
||||||
description = "Code coverage measurement for Python"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dff044f661f59dace805eedb4a7404c573b6ff0cdba4a524141bc63d7be5c7fd"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a8659fd33ee9e6ca03950cfdcdf271d645cf681609153f218826dd9805ab585c"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7792f0ab20df8071d669d929c75c97fecfa6bcab82c10ee4adb91c7a54055463"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d4b3cd1ca7cd73d229487fa5caca9e4bc1f0bca96526b922d61053ea751fe791"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e7e128f85c0b419907d1f38e616c4f1e9f1d1b37a7949f44df9a73d5da5cd53c"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a94925102c89247530ae1dab7dc02c690942566f22e189cbd53579b0693c0783"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:dcd070b5b585b50e6617e8972f3fbbee786afca71b1936ac06257f7e178f00f6"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:d50a252b23b9b4dfeefc1f663c568a221092cbaded20a05a11665d0dbec9b8fb"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-win32.whl", hash = "sha256:0e7b27d04131c46e6894f23a4ae186a6a2207209a05df5b6ad4caee6d54a222c"},
|
|
||||||
{file = "coverage-7.6.0-cp310-cp310-win_amd64.whl", hash = "sha256:54dece71673b3187c86226c3ca793c5f891f9fc3d8aa183f2e3653da18566169"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c7b525ab52ce18c57ae232ba6f7010297a87ced82a2383b1afd238849c1ff933"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bea27c4269234e06f621f3fac3925f56ff34bc14521484b8f66a580aacc2e7d"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed8d1d1821ba5fc88d4a4f45387b65de52382fa3ef1f0115a4f7a20cdfab0e94"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:01c322ef2bbe15057bc4bf132b525b7e3f7206f071799eb8aa6ad1940bcf5fb1"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:03cafe82c1b32b770a29fd6de923625ccac3185a54a5e66606da26d105f37dac"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:0d1b923fc4a40c5832be4f35a5dab0e5ff89cddf83bb4174499e02ea089daf57"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:4b03741e70fb811d1a9a1d75355cf391f274ed85847f4b78e35459899f57af4d"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:a73d18625f6a8a1cbb11eadc1d03929f9510f4131879288e3f7922097a429f63"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-win32.whl", hash = "sha256:65fa405b837060db569a61ec368b74688f429b32fa47a8929a7a2f9b47183713"},
|
|
||||||
{file = "coverage-7.6.0-cp311-cp311-win_amd64.whl", hash = "sha256:6379688fb4cfa921ae349c76eb1a9ab26b65f32b03d46bb0eed841fd4cb6afb1"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f7db0b6ae1f96ae41afe626095149ecd1b212b424626175a6633c2999eaad45b"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:bbdf9a72403110a3bdae77948b8011f644571311c2fb35ee15f0f10a8fc082e8"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9cc44bf0315268e253bf563f3560e6c004efe38f76db03a1558274a6e04bf5d5"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:da8549d17489cd52f85a9829d0e1d91059359b3c54a26f28bec2c5d369524807"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0086cd4fc71b7d485ac93ca4239c8f75732c2ae3ba83f6be1c9be59d9e2c6382"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:1fad32ee9b27350687035cb5fdf9145bc9cf0a094a9577d43e909948ebcfa27b"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:044a0985a4f25b335882b0966625270a8d9db3d3409ddc49a4eb00b0ef5e8cee"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:76d5f82213aa78098b9b964ea89de4617e70e0d43e97900c2778a50856dac605"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-win32.whl", hash = "sha256:3c59105f8d58ce500f348c5b56163a4113a440dad6daa2294b5052a10db866da"},
|
|
||||||
{file = "coverage-7.6.0-cp312-cp312-win_amd64.whl", hash = "sha256:ca5d79cfdae420a1d52bf177de4bc2289c321d6c961ae321503b2ca59c17ae67"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d39bd10f0ae453554798b125d2f39884290c480f56e8a02ba7a6ed552005243b"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:beb08e8508e53a568811016e59f3234d29c2583f6b6e28572f0954a6b4f7e03d"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b2e16f4cd2bc4d88ba30ca2d3bbf2f21f00f382cf4e1ce3b1ddc96c634bc48ca"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6616d1c9bf1e3faea78711ee42a8b972367d82ceae233ec0ac61cc7fec09fa6b"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ad4567d6c334c46046d1c4c20024de2a1c3abc626817ae21ae3da600f5779b44"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:d17c6a415d68cfe1091d3296ba5749d3d8696e42c37fca5d4860c5bf7b729f03"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:9146579352d7b5f6412735d0f203bbd8d00113a680b66565e205bc605ef81bc6"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:cdab02a0a941af190df8782aafc591ef3ad08824f97850b015c8c6a8b3877b0b"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-win32.whl", hash = "sha256:df423f351b162a702c053d5dddc0fc0ef9a9e27ea3f449781ace5f906b664428"},
|
|
||||||
{file = "coverage-7.6.0-cp38-cp38-win_amd64.whl", hash = "sha256:f2501d60d7497fd55e391f423f965bbe9e650e9ffc3c627d5f0ac516026000b8"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7221f9ac9dad9492cecab6f676b3eaf9185141539d5c9689d13fd6b0d7de840c"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ddaaa91bfc4477d2871442bbf30a125e8fe6b05da8a0015507bfbf4718228ab2"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c4cbe651f3904e28f3a55d6f371203049034b4ddbce65a54527a3f189ca3b390"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:831b476d79408ab6ccfadaaf199906c833f02fdb32c9ab907b1d4aa0713cfa3b"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:46c3d091059ad0b9c59d1034de74a7f36dcfa7f6d3bde782c49deb42438f2450"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:4d5fae0a22dc86259dee66f2cc6c1d3e490c4a1214d7daa2a93d07491c5c04b6"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:07ed352205574aad067482e53dd606926afebcb5590653121063fbf4e2175166"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:49c76cdfa13015c4560702574bad67f0e15ca5a2872c6a125f6327ead2b731dd"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-win32.whl", hash = "sha256:482855914928c8175735a2a59c8dc5806cf7d8f032e4820d52e845d1f731dca2"},
|
|
||||||
{file = "coverage-7.6.0-cp39-cp39-win_amd64.whl", hash = "sha256:543ef9179bc55edfd895154a51792b01c017c87af0ebaae092720152e19e42ca"},
|
|
||||||
{file = "coverage-7.6.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:6fe885135c8a479d3e37a7aae61cbd3a0fb2deccb4dda3c25f92a49189f766d6"},
|
|
||||||
{file = "coverage-7.6.0.tar.gz", hash = "sha256:289cc803fa1dc901f84701ac10c9ee873619320f2f9aff38794db4a4a0268d51"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
toml = ["tomli"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "distlib"
|
|
||||||
version = "0.3.8"
|
|
||||||
description = "Distribution utilities"
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
files = [
|
|
||||||
{file = "distlib-0.3.8-py2.py3-none-any.whl", hash = "sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784"},
|
|
||||||
{file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "filelock"
|
|
||||||
version = "3.15.4"
|
|
||||||
description = "A platform independent file lock."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "filelock-3.15.4-py3-none-any.whl", hash = "sha256:6ca1fffae96225dab4c6eaf1c4f4f28cd2568d3ec2a44e15a08520504de468e7"},
|
|
||||||
{file = "filelock-3.15.4.tar.gz", hash = "sha256:2207938cbc1844345cb01a5a95524dae30f0ce089eba5b00378295a17e3e90cb"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
docs = ["furo (>=2023.9.10)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"]
|
|
||||||
testing = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "diff-cover (>=8.0.1)", "pytest (>=7.4.3)", "pytest-asyncio (>=0.21)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)", "pytest-timeout (>=2.2)", "virtualenv (>=20.26.2)"]
|
|
||||||
typing = ["typing-extensions (>=4.8)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "identify"
|
|
||||||
version = "2.6.0"
|
|
||||||
description = "File identification library for Python"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "identify-2.6.0-py2.py3-none-any.whl", hash = "sha256:e79ae4406387a9d300332b5fd366d8994f1525e8414984e1a59e058b2eda2dd0"},
|
|
||||||
{file = "identify-2.6.0.tar.gz", hash = "sha256:cb171c685bdc31bcc4c1734698736a7d5b6c8bf2e0c15117f4d469c8640ae5cf"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
license = ["ukkonen"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "isort"
|
|
||||||
version = "5.13.2"
|
|
||||||
description = "A Python utility / library to sort Python imports."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8.0"
|
|
||||||
files = [
|
|
||||||
{file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"},
|
|
||||||
{file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
colors = ["colorama (>=0.4.6)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mypy-extensions"
|
|
||||||
version = "1.0.0"
|
|
||||||
description = "Type system extensions for programs checked with the mypy type checker."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.5"
|
|
||||||
files = [
|
|
||||||
{file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"},
|
|
||||||
{file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nodeenv"
|
|
||||||
version = "1.9.1"
|
|
||||||
description = "Node.js virtual environment builder"
|
|
||||||
optional = false
|
|
||||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
|
||||||
files = [
|
|
||||||
{file = "nodeenv-1.9.1-py2.py3-none-any.whl", hash = "sha256:ba11c9782d29c27c70ffbdda2d7415098754709be8a7056d79a737cd901155c9"},
|
|
||||||
{file = "nodeenv-1.9.1.tar.gz", hash = "sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nptyping"
|
|
||||||
version = "2.5.0"
|
|
||||||
description = "Type hints for NumPy."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
files = [
|
|
||||||
{file = "nptyping-2.5.0-py3-none-any.whl", hash = "sha256:764e51836faae33a7ae2e928af574cfb701355647accadcc89f2ad793630b7c8"},
|
|
||||||
{file = "nptyping-2.5.0.tar.gz", hash = "sha256:e3d35b53af967e6fb407c3016ff9abae954d3a0568f7cc13a461084224e8e20a"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
numpy = {version = ">=1.20.0,<2.0.0", markers = "python_version >= \"3.8\""}
|
|
||||||
typing-extensions = {version = ">=4.0.0,<5.0.0", markers = "python_version < \"3.10\""}
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
build = ["invoke (>=1.6.0)", "pip-tools (>=6.5.0)"]
|
|
||||||
complete = ["pandas", "pandas-stubs-fork"]
|
|
||||||
dev = ["autoflake", "beartype (<0.10.0)", "beartype (>=0.10.0)", "black", "codecov (>=2.1.0)", "coverage", "feedparser", "invoke (>=1.6.0)", "isort", "mypy", "pandas", "pandas-stubs-fork", "pip-tools (>=6.5.0)", "pylint", "pyright", "setuptools", "typeguard", "wheel"]
|
|
||||||
pandas = ["pandas", "pandas-stubs-fork"]
|
|
||||||
qa = ["autoflake", "beartype (<0.10.0)", "beartype (>=0.10.0)", "black", "codecov (>=2.1.0)", "coverage", "feedparser", "isort", "mypy", "pylint", "pyright", "setuptools", "typeguard", "wheel"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "numpy"
|
|
||||||
version = "1.26.4"
|
|
||||||
description = "Fundamental package for array computing in Python"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.9"
|
|
||||||
files = [
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9ff0f4f29c51e2803569d7a51c2304de5554655a60c5d776e35b4a41413830d0"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2e4ee3380d6de9c9ec04745830fd9e2eccb3e6cf790d39d7b98ffd19b0dd754a"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d209d8969599b27ad20994c8e41936ee0964e6da07478d6c35016bc386b66ad4"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ffa75af20b44f8dba823498024771d5ac50620e6915abac414251bd971b4529f"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:62b8e4b1e28009ef2846b4c7852046736bab361f7aeadeb6a5b89ebec3c7055a"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:a4abb4f9001ad2858e7ac189089c42178fcce737e4169dc61321660f1a96c7d2"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-win32.whl", hash = "sha256:bfe25acf8b437eb2a8b2d49d443800a5f18508cd811fea3181723922a8a82b07"},
|
|
||||||
{file = "numpy-1.26.4-cp310-cp310-win_amd64.whl", hash = "sha256:b97fe8060236edf3662adfc2c633f56a08ae30560c56310562cb4f95500022d5"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4c66707fabe114439db9068ee468c26bbdf909cac0fb58686a42a24de1760c71"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:edd8b5fe47dab091176d21bb6de568acdd906d1887a4584a15a9a96a1dca06ef"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7ab55401287bfec946ced39700c053796e7cc0e3acbef09993a9ad2adba6ca6e"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:666dbfb6ec68962c033a450943ded891bed2d54e6755e35e5835d63f4f6931d5"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:96ff0b2ad353d8f990b63294c8986f1ec3cb19d749234014f4e7eb0112ceba5a"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:60dedbb91afcbfdc9bc0b1f3f402804070deed7392c23eb7a7f07fa857868e8a"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-win32.whl", hash = "sha256:1af303d6b2210eb850fcf03064d364652b7120803a0b872f5211f5234b399f20"},
|
|
||||||
{file = "numpy-1.26.4-cp311-cp311-win_amd64.whl", hash = "sha256:cd25bcecc4974d09257ffcd1f098ee778f7834c3ad767fe5db785be9a4aa9cb2"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:b3ce300f3644fb06443ee2222c2201dd3a89ea6040541412b8fa189341847218"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:03a8c78d01d9781b28a6989f6fa1bb2c4f2d51201cf99d3dd875df6fbd96b23b"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9fad7dcb1aac3c7f0584a5a8133e3a43eeb2fe127f47e3632d43d677c66c102b"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:675d61ffbfa78604709862923189bad94014bef562cc35cf61d3a07bba02a7ed"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:ab47dbe5cc8210f55aa58e4805fe224dac469cde56b9f731a4c098b91917159a"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:1dda2e7b4ec9dd512f84935c5f126c8bd8b9f2fc001e9f54af255e8c5f16b0e0"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-win32.whl", hash = "sha256:50193e430acfc1346175fcbdaa28ffec49947a06918b7b92130744e81e640110"},
|
|
||||||
{file = "numpy-1.26.4-cp312-cp312-win_amd64.whl", hash = "sha256:08beddf13648eb95f8d867350f6a018a4be2e5ad54c8d8caed89ebca558b2818"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7349ab0fa0c429c82442a27a9673fc802ffdb7c7775fad780226cb234965e53c"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:52b8b60467cd7dd1e9ed082188b4e6bb35aa5cdd01777621a1658910745b90be"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d5241e0a80d808d70546c697135da2c613f30e28251ff8307eb72ba696945764"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f870204a840a60da0b12273ef34f7051e98c3b5961b61b0c2c1be6dfd64fbcd3"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:679b0076f67ecc0138fd2ede3a8fd196dddc2ad3254069bcb9faf9a79b1cebcd"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:47711010ad8555514b434df65f7d7b076bb8261df1ca9bb78f53d3b2db02e95c"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-win32.whl", hash = "sha256:a354325ee03388678242a4d7ebcd08b5c727033fcff3b2f536aea978e15ee9e6"},
|
|
||||||
{file = "numpy-1.26.4-cp39-cp39-win_amd64.whl", hash = "sha256:3373d5d70a5fe74a2c1bb6d2cfd9609ecf686d47a2d7b1d37a8f3b6bf6003aea"},
|
|
||||||
{file = "numpy-1.26.4-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:afedb719a9dcfc7eaf2287b839d8198e06dcd4cb5d276a3df279231138e83d30"},
|
|
||||||
{file = "numpy-1.26.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:95a7476c59002f2f6c590b9b7b998306fba6a5aa646b1e22ddfeaf8f78c3a29c"},
|
|
||||||
{file = "numpy-1.26.4-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7e50d0a0cc3189f9cb0aeb3a6a6af18c16f59f004b866cd2be1c14b36134a4a0"},
|
|
||||||
{file = "numpy-1.26.4.tar.gz", hash = "sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "packaging"
|
|
||||||
version = "24.1"
|
|
||||||
description = "Core utilities for Python packages"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"},
|
|
||||||
{file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pastel"
|
|
||||||
version = "0.2.1"
|
|
||||||
description = "Bring colors to your terminal."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
|
||||||
files = [
|
|
||||||
{file = "pastel-0.2.1-py2.py3-none-any.whl", hash = "sha256:4349225fcdf6c2bb34d483e523475de5bb04a5c10ef711263452cb37d7dd4364"},
|
|
||||||
{file = "pastel-0.2.1.tar.gz", hash = "sha256:e6581ac04e973cac858828c6202c1e1e81fee1dc7de7683f3e1ffe0bfd8a573d"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pathspec"
|
|
||||||
version = "0.12.1"
|
|
||||||
description = "Utility library for gitignore style pattern matching of file paths."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"},
|
|
||||||
{file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "platformdirs"
|
|
||||||
version = "4.2.2"
|
|
||||||
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "platformdirs-4.2.2-py3-none-any.whl", hash = "sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee"},
|
|
||||||
{file = "platformdirs-4.2.2.tar.gz", hash = "sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"]
|
|
||||||
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"]
|
|
||||||
type = ["mypy (>=1.8)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "poethepoet"
|
|
||||||
version = "0.27.0"
|
|
||||||
description = "A task runner that works well with poetry."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "poethepoet-0.27.0-py3-none-any.whl", hash = "sha256:0032d980a623b96e26dc7450ae200b0998be523f27d297d799b97510fe252a24"},
|
|
||||||
{file = "poethepoet-0.27.0.tar.gz", hash = "sha256:907ab4dc1bc6326be5a3b10d2aa39d1acc0ca12024317d9506fbe9c0cdc912c9"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
pastel = ">=0.2.1,<0.3.0"
|
|
||||||
tomli = ">=1.2.2"
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
poetry-plugin = ["poetry (>=1.0,<2.0)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pre-commit"
|
|
||||||
version = "3.7.1"
|
|
||||||
description = "A framework for managing and maintaining multi-language pre-commit hooks."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.9"
|
|
||||||
files = [
|
|
||||||
{file = "pre_commit-3.7.1-py2.py3-none-any.whl", hash = "sha256:fae36fd1d7ad7d6a5a1c0b0d5adb2ed1a3bda5a21bf6c3e5372073d7a11cd4c5"},
|
|
||||||
{file = "pre_commit-3.7.1.tar.gz", hash = "sha256:8ca3ad567bc78a4972a3f1a477e94a79d4597e8140a6e0b651c5e33899c3654a"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
cfgv = ">=2.0.0"
|
|
||||||
identify = ">=1.0.0"
|
|
||||||
nodeenv = ">=0.11.1"
|
|
||||||
pyyaml = ">=5.1"
|
|
||||||
virtualenv = ">=20.10.0"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pyyaml"
|
|
||||||
version = "6.0.1"
|
|
||||||
description = "YAML parser and emitter for Python"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.6"
|
|
||||||
files = [
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"},
|
|
||||||
{file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"},
|
|
||||||
{file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"},
|
|
||||||
{file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"},
|
|
||||||
{file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"},
|
|
||||||
{file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"},
|
|
||||||
{file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"},
|
|
||||||
{file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd"},
|
|
||||||
{file = "PyYAML-6.0.1-cp36-cp36m-win32.whl", hash = "sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585"},
|
|
||||||
{file = "PyYAML-6.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa"},
|
|
||||||
{file = "PyYAML-6.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3"},
|
|
||||||
{file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27"},
|
|
||||||
{file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3"},
|
|
||||||
{file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c"},
|
|
||||||
{file = "PyYAML-6.0.1-cp37-cp37m-win32.whl", hash = "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba"},
|
|
||||||
{file = "PyYAML-6.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"},
|
|
||||||
{file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"},
|
|
||||||
{file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"},
|
|
||||||
{file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "setproctitle"
|
|
||||||
version = "1.3.3"
|
|
||||||
description = "A Python module to customize the process title"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
files = [
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:897a73208da48db41e687225f355ce993167079eda1260ba5e13c4e53be7f754"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:8c331e91a14ba4076f88c29c777ad6b58639530ed5b24b5564b5ed2fd7a95452"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bbbd6c7de0771c84b4aa30e70b409565eb1fc13627a723ca6be774ed6b9d9fa3"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c05ac48ef16ee013b8a326c63e4610e2430dbec037ec5c5b58fcced550382b74"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1342f4fdb37f89d3e3c1c0a59d6ddbedbde838fff5c51178a7982993d238fe4f"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fc74e84fdfa96821580fb5e9c0b0777c1c4779434ce16d3d62a9c4d8c710df39"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:9617b676b95adb412bb69645d5b077d664b6882bb0d37bfdafbbb1b999568d85"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:6a249415f5bb88b5e9e8c4db47f609e0bf0e20a75e8d744ea787f3092ba1f2d0"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:38da436a0aaace9add67b999eb6abe4b84397edf4a78ec28f264e5b4c9d53cd5"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:da0d57edd4c95bf221b2ebbaa061e65b1788f1544977288bdf95831b6e44e44d"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-win32.whl", hash = "sha256:a1fcac43918b836ace25f69b1dca8c9395253ad8152b625064415b1d2f9be4fb"},
|
|
||||||
{file = "setproctitle-1.3.3-cp310-cp310-win_amd64.whl", hash = "sha256:200620c3b15388d7f3f97e0ae26599c0c378fdf07ae9ac5a13616e933cbd2086"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:334f7ed39895d692f753a443102dd5fed180c571eb6a48b2a5b7f5b3564908c8"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:950f6476d56ff7817a8fed4ab207727fc5260af83481b2a4b125f32844df513a"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:195c961f54a09eb2acabbfc90c413955cf16c6e2f8caa2adbf2237d1019c7dd8"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f05e66746bf9fe6a3397ec246fe481096664a9c97eb3fea6004735a4daf867fd"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b5901a31012a40ec913265b64e48c2a4059278d9f4e6be628441482dd13fb8b5"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:64286f8a995f2cd934082b398fc63fca7d5ffe31f0e27e75b3ca6b4efda4e353"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:184239903bbc6b813b1a8fc86394dc6ca7d20e2ebe6f69f716bec301e4b0199d"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:664698ae0013f986118064b6676d7dcd28fefd0d7d5a5ae9497cbc10cba48fa5"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:e5119a211c2e98ff18b9908ba62a3bd0e3fabb02a29277a7232a6fb4b2560aa0"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:417de6b2e214e837827067048f61841f5d7fc27926f2e43954567094051aff18"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-win32.whl", hash = "sha256:6a143b31d758296dc2f440175f6c8e0b5301ced3b0f477b84ca43cdcf7f2f476"},
|
|
||||||
{file = "setproctitle-1.3.3-cp311-cp311-win_amd64.whl", hash = "sha256:a680d62c399fa4b44899094027ec9a1bdaf6f31c650e44183b50d4c4d0ccc085"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:d4460795a8a7a391e3567b902ec5bdf6c60a47d791c3b1d27080fc203d11c9dc"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:bdfd7254745bb737ca1384dee57e6523651892f0ea2a7344490e9caefcc35e64"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:477d3da48e216d7fc04bddab67b0dcde633e19f484a146fd2a34bb0e9dbb4a1e"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ab2900d111e93aff5df9fddc64cf51ca4ef2c9f98702ce26524f1acc5a786ae7"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:088b9efc62d5aa5d6edf6cba1cf0c81f4488b5ce1c0342a8b67ae39d64001120"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a6d50252377db62d6a0bb82cc898089916457f2db2041e1d03ce7fadd4a07381"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:87e668f9561fd3a457ba189edfc9e37709261287b52293c115ae3487a24b92f6"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:287490eb90e7a0ddd22e74c89a92cc922389daa95babc833c08cf80c84c4df0a"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:4fe1c49486109f72d502f8be569972e27f385fe632bd8895f4730df3c87d5ac8"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4a6ba2494a6449b1f477bd3e67935c2b7b0274f2f6dcd0f7c6aceae10c6c6ba3"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-win32.whl", hash = "sha256:2df2b67e4b1d7498632e18c56722851ba4db5d6a0c91aaf0fd395111e51cdcf4"},
|
|
||||||
{file = "setproctitle-1.3.3-cp312-cp312-win_amd64.whl", hash = "sha256:f38d48abc121263f3b62943f84cbaede05749047e428409c2c199664feb6abc7"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:816330675e3504ae4d9a2185c46b573105d2310c20b19ea2b4596a9460a4f674"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:68f960bc22d8d8e4ac886d1e2e21ccbd283adcf3c43136161c1ba0fa509088e0"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:00e6e7adff74796ef12753ff399491b8827f84f6c77659d71bd0b35870a17d8f"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:53bc0d2358507596c22b02db079618451f3bd720755d88e3cccd840bafb4c41c"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ad6d20f9541f5f6ac63df553b6d7a04f313947f550eab6a61aa758b45f0d5657"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:c1c84beab776b0becaa368254801e57692ed749d935469ac10e2b9b825dbdd8e"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:507e8dc2891021350eaea40a44ddd887c9f006e6b599af8d64a505c0f718f170"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:b1067647ac7aba0b44b591936118a22847bda3c507b0a42d74272256a7a798e9"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:2e71f6365744bf53714e8bd2522b3c9c1d83f52ffa6324bd7cbb4da707312cd8"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-win32.whl", hash = "sha256:7f1d36a1e15a46e8ede4e953abb104fdbc0845a266ec0e99cc0492a4364f8c44"},
|
|
||||||
{file = "setproctitle-1.3.3-cp37-cp37m-win_amd64.whl", hash = "sha256:c9a402881ec269d0cc9c354b149fc29f9ec1a1939a777f1c858cdb09c7a261df"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:ff814dea1e5c492a4980e3e7d094286077054e7ea116cbeda138819db194b2cd"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:accb66d7b3ccb00d5cd11d8c6e07055a4568a24c95cf86109894dcc0c134cc89"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:554eae5a5b28f02705b83a230e9d163d645c9a08914c0ad921df363a07cf39b1"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a911b26264dbe9e8066c7531c0591cfab27b464459c74385b276fe487ca91c12"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2982efe7640c4835f7355fdb4da313ad37fb3b40f5c69069912f8048f77b28c8"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:df3f4274b80709d8bcab2f9a862973d453b308b97a0b423a501bcd93582852e3"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:af2c67ae4c795d1674a8d3ac1988676fa306bcfa1e23fddb5e0bd5f5635309ca"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:af4061f67fd7ec01624c5e3c21f6b7af2ef0e6bab7fbb43f209e6506c9ce0092"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:37a62cbe16d4c6294e84670b59cf7adcc73faafe6af07f8cb9adaf1f0e775b19"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:a83ca086fbb017f0d87f240a8f9bbcf0809f3b754ee01cec928fff926542c450"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-win32.whl", hash = "sha256:059f4ce86f8cc92e5860abfc43a1dceb21137b26a02373618d88f6b4b86ba9b2"},
|
|
||||||
{file = "setproctitle-1.3.3-cp38-cp38-win_amd64.whl", hash = "sha256:ab92e51cd4a218208efee4c6d37db7368fdf182f6e7ff148fb295ecddf264287"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:c7951820b77abe03d88b114b998867c0f99da03859e5ab2623d94690848d3e45"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:5bc94cf128676e8fac6503b37763adb378e2b6be1249d207630f83fc325d9b11"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f5d9027eeda64d353cf21a3ceb74bb1760bd534526c9214e19f052424b37e42"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e4a8104db15d3462e29d9946f26bed817a5b1d7a47eabca2d9dc2b995991503"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c32c41ace41f344d317399efff4cffb133e709cec2ef09c99e7a13e9f3b9483c"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cbf16381c7bf7f963b58fb4daaa65684e10966ee14d26f5cc90f07049bfd8c1e"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:e18b7bd0898398cc97ce2dfc83bb192a13a087ef6b2d5a8a36460311cb09e775"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:69d565d20efe527bd8a9b92e7f299ae5e73b6c0470f3719bd66f3cd821e0d5bd"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:ddedd300cd690a3b06e7eac90ed4452348b1348635777ce23d460d913b5b63c3"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:415bfcfd01d1fbf5cbd75004599ef167a533395955305f42220a585f64036081"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-win32.whl", hash = "sha256:21112fcd2195d48f25760f0eafa7a76510871bbb3b750219310cf88b04456ae3"},
|
|
||||||
{file = "setproctitle-1.3.3-cp39-cp39-win_amd64.whl", hash = "sha256:5a740f05d0968a5a17da3d676ce6afefebeeeb5ce137510901bf6306ba8ee002"},
|
|
||||||
{file = "setproctitle-1.3.3-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:6b9e62ddb3db4b5205c0321dd69a406d8af9ee1693529d144e86bd43bcb4b6c0"},
|
|
||||||
{file = "setproctitle-1.3.3-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9e3b99b338598de0bd6b2643bf8c343cf5ff70db3627af3ca427a5e1a1a90dd9"},
|
|
||||||
{file = "setproctitle-1.3.3-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:38ae9a02766dad331deb06855fb7a6ca15daea333b3967e214de12cfae8f0ef5"},
|
|
||||||
{file = "setproctitle-1.3.3-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:200ede6fd11233085ba9b764eb055a2a191fb4ffb950c68675ac53c874c22e20"},
|
|
||||||
{file = "setproctitle-1.3.3-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:0d3a953c50776751e80fe755a380a64cb14d61e8762bd43041ab3f8cc436092f"},
|
|
||||||
{file = "setproctitle-1.3.3-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e5e08e232b78ba3ac6bc0d23ce9e2bee8fad2be391b7e2da834fc9a45129eb87"},
|
|
||||||
{file = "setproctitle-1.3.3-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f1da82c3e11284da4fcbf54957dafbf0655d2389cd3d54e4eaba636faf6d117a"},
|
|
||||||
{file = "setproctitle-1.3.3-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:aeaa71fb9568ebe9b911ddb490c644fbd2006e8c940f21cb9a1e9425bd709574"},
|
|
||||||
{file = "setproctitle-1.3.3-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:59335d000c6250c35989394661eb6287187854e94ac79ea22315469ee4f4c244"},
|
|
||||||
{file = "setproctitle-1.3.3-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c3ba57029c9c50ecaf0c92bb127224cc2ea9fda057b5d99d3f348c9ec2855ad3"},
|
|
||||||
{file = "setproctitle-1.3.3-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d876d355c53d975c2ef9c4f2487c8f83dad6aeaaee1b6571453cb0ee992f55f6"},
|
|
||||||
{file = "setproctitle-1.3.3-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:224602f0939e6fb9d5dd881be1229d485f3257b540f8a900d4271a2c2aa4e5f4"},
|
|
||||||
{file = "setproctitle-1.3.3-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:d7f27e0268af2d7503386e0e6be87fb9b6657afd96f5726b733837121146750d"},
|
|
||||||
{file = "setproctitle-1.3.3-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f5e7266498cd31a4572378c61920af9f6b4676a73c299fce8ba93afd694f8ae7"},
|
|
||||||
{file = "setproctitle-1.3.3-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:33c5609ad51cd99d388e55651b19148ea99727516132fb44680e1f28dd0d1de9"},
|
|
||||||
{file = "setproctitle-1.3.3-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:eae8988e78192fd1a3245a6f4f382390b61bce6cfcc93f3809726e4c885fa68d"},
|
|
||||||
{file = "setproctitle-1.3.3.tar.gz", hash = "sha256:c913e151e7ea01567837ff037a23ca8740192880198b7fbb90b16d181607caae"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
test = ["pytest"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tomli"
|
|
||||||
version = "2.0.1"
|
|
||||||
description = "A lil' TOML parser"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
files = [
|
|
||||||
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
|
|
||||||
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typing-extensions"
|
|
||||||
version = "4.12.2"
|
|
||||||
description = "Backported and Experimental Type Hints for Python 3.8+"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
files = [
|
|
||||||
{file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"},
|
|
||||||
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "virtualenv"
|
|
||||||
version = "20.26.3"
|
|
||||||
description = "Virtual Python Environment builder"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
files = [
|
|
||||||
{file = "virtualenv-20.26.3-py3-none-any.whl", hash = "sha256:8cc4a31139e796e9a7de2cd5cf2489de1217193116a8fd42328f1bd65f434589"},
|
|
||||||
{file = "virtualenv-20.26.3.tar.gz", hash = "sha256:4c43a2a236279d9ea36a0d76f98d84bd6ca94ac4e0f4a3b9d46d05e10fea542a"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
distlib = ">=0.3.7,<1"
|
|
||||||
filelock = ">=3.12.2,<4"
|
|
||||||
platformdirs = ">=3.9.1,<5"
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"]
|
|
||||||
test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"]
|
|
||||||
|
|
||||||
[metadata]
|
|
||||||
lock-version = "2.0"
|
|
||||||
python-versions = ">=3.9,<4.0"
|
|
||||||
content-hash = "80ecbda1b826475e5eef19c940136c907a9687c7f4a6a0577a65ddd9b8a3343b"
|
|
||||||
106
pyproject.toml
106
pyproject.toml
@@ -1,47 +1,83 @@
|
|||||||
[tool.poetry]
|
[project]
|
||||||
name = "diceplayer"
|
name = "diceplayer"
|
||||||
version = "0.0.0"
|
description = "Python Program for Molecular Optimization in Non-Vacuum Mediums"
|
||||||
description = ""
|
authors = [
|
||||||
authors = ["Vitor Hideyoshi <vitor.h.n.batista@gmail.com>", "Herbert Georg <hcgeorg@ufg.br>"]
|
{ name = "Vitor Hideyoshi", email = "vitor.h.n.batista@gmail.com" },
|
||||||
license = "GPL-2.0-only"
|
{ name = "Herbert Georg", email = "hcgeorg@ufg.br" }
|
||||||
|
]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
license = "GPL-2.0-only"
|
||||||
|
scripts = { diceplayer = "diceplayer.__main__:main" }
|
||||||
|
requires-python = ">=3.10"
|
||||||
|
dynamic = ["version"]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
|
||||||
python = ">=3.9,<4.0"
|
|
||||||
numpy = "^1.26.4"
|
|
||||||
argparse = "^1.4.0"
|
|
||||||
setproctitle = "^1.3.2"
|
|
||||||
pyyaml = "^6.0"
|
|
||||||
nptyping = "^2.5.0"
|
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
dependencies = [
|
||||||
diceplayer = "diceplayer.__main__:main"
|
"numpy>=2.2.0",
|
||||||
|
"argparse>=1.4.0",
|
||||||
|
"setproctitle>=1.3.2",
|
||||||
|
"pyyaml>=6.0",
|
||||||
|
"pydantic>=2.12.5",
|
||||||
|
"typing-extensions>=4.15.0"
|
||||||
|
]
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
|
||||||
coverage = "^7.2.7"
|
|
||||||
isort = "^5.13.2"
|
|
||||||
black = "^24.4.2"
|
|
||||||
pre-commit = "^3.7.1"
|
|
||||||
poethepoet = "^0.27.0"
|
|
||||||
|
|
||||||
[tool.poetry-dynamic-versioning]
|
[dependency-groups]
|
||||||
enable = true
|
dev = [
|
||||||
vcs = "git"
|
"coverage>=7.2.7",
|
||||||
|
"isort>=5.13.2",
|
||||||
|
"black>=24.4.2",
|
||||||
|
"pre-commit>=3.7.1",
|
||||||
|
"poethepoet>=0.27.0",
|
||||||
|
"ruff>=0.15.2",
|
||||||
|
"pytest>=9.0.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Build system
|
||||||
|
[tool.hatch.version]
|
||||||
|
source = "vcs"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["hatchling", "hatch-vcs"]
|
||||||
build-backend = "poetry_dynamic_versioning.backend"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
|
||||||
|
# POE Tasks
|
||||||
[tool.poe.tasks]
|
[tool.poe.tasks]
|
||||||
hooks = "pre-commit install --config .pre-commit-config.yaml"
|
create-hooks = "bash .githooks/set-hooks.sh"
|
||||||
|
tests = "python -m coverage run -m unittest discover -v"
|
||||||
|
tests-report = "python -m coverage xml"
|
||||||
|
|
||||||
[tool.isort]
|
|
||||||
profile = "black"
|
|
||||||
line_length = 79
|
# Tests
|
||||||
sections=[
|
[tool.coverage.run]
|
||||||
"FUTURE",
|
omit = [
|
||||||
"FIRSTPARTY",
|
"tests/*",
|
||||||
"LOCALFOLDER",
|
|
||||||
"THIRDPARTY",
|
|
||||||
"STDLIB",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Linters
|
||||||
|
[tool.ruff.lint]
|
||||||
|
extend-select = ["I"]
|
||||||
|
ignore = [
|
||||||
|
"E741" # ambiguous variable name 'l', 'O', or 'I'
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
known-first-party = ["jambo"]
|
||||||
|
section-order=[
|
||||||
|
"future",
|
||||||
|
"first-party",
|
||||||
|
"local-folder",
|
||||||
|
"third-party",
|
||||||
|
"standard-library",
|
||||||
|
]
|
||||||
|
lines-after-imports = 2
|
||||||
|
|
||||||
|
|
||||||
|
[tool.pyright]
|
||||||
|
venvPath = "."
|
||||||
|
venv = ".venv"
|
||||||
|
|||||||
30
tests/cli/test_read_input_file.py
Normal file
30
tests/cli/test_read_input_file.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import diceplayer
|
||||||
|
from diceplayer.cli import read_input
|
||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class TestReadInputFile:
|
||||||
|
@pytest.fixture
|
||||||
|
def example_config(self) -> Path:
|
||||||
|
return Path(diceplayer.__path__[0]).parent / "control.example.yml"
|
||||||
|
|
||||||
|
def test_read_input_file(self, example_config: Path):
|
||||||
|
config = read_input(example_config)
|
||||||
|
|
||||||
|
assert config is not None
|
||||||
|
assert isinstance(config, PlayerConfig)
|
||||||
|
|
||||||
|
def test_read_input_non_existing_file(self):
|
||||||
|
with pytest.raises(FileNotFoundError):
|
||||||
|
read_input("nonexistent_file.yml")
|
||||||
|
|
||||||
|
def test_read_input_invalid_yaml(self, tmp_path: Path):
|
||||||
|
invalid_yaml_file = tmp_path / "invalid.yml"
|
||||||
|
invalid_yaml_file.write_text("This is not valid YAML: [unbalanced brackets")
|
||||||
|
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
read_input(invalid_yaml_file)
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
from diceplayer.shared.config.dice_config import DiceConfig
|
from diceplayer.config.dice_config import DiceConfig
|
||||||
|
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class TestDiceDto(unittest.TestCase):
|
class TestDiceConfig:
|
||||||
def test_class_instantiation(self):
|
def test_class_instantiation(self):
|
||||||
dice_dto = DiceConfig(
|
dice_dto = DiceConfig(
|
||||||
|
nprocs=1,
|
||||||
ljname="test",
|
ljname="test",
|
||||||
outname="test",
|
outname="test",
|
||||||
dens=1.0,
|
dens=1.0,
|
||||||
@@ -13,78 +14,77 @@ class TestDiceDto(unittest.TestCase):
|
|||||||
nstep=[1, 1],
|
nstep=[1, 1],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertIsInstance(dice_dto, DiceConfig)
|
assert isinstance(dice_dto, DiceConfig)
|
||||||
|
|
||||||
def test_validate_jname(self):
|
def test_validate_jname(self):
|
||||||
with self.assertRaises(ValueError) as ex:
|
with pytest.raises(ValueError) as ex:
|
||||||
DiceConfig(
|
DiceConfig(
|
||||||
|
nprocs=1,
|
||||||
ljname=None,
|
ljname=None,
|
||||||
outname="test",
|
outname="test",
|
||||||
dens=1.0,
|
dens=1.0,
|
||||||
nmol=[1],
|
nmol=[1],
|
||||||
nstep=[1, 1],
|
nstep=[1, 1],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
ex.exception, "Error: 'ljname' keyword not specified in config file"
|
assert ex.value == "Error: 'ljname' keyword not specified in config file"
|
||||||
)
|
|
||||||
|
|
||||||
def test_validate_outname(self):
|
def test_validate_outname(self):
|
||||||
with self.assertRaises(ValueError) as ex:
|
with pytest.raises(ValueError) as ex:
|
||||||
DiceConfig(
|
DiceConfig(
|
||||||
|
nprocs=1,
|
||||||
ljname="test",
|
ljname="test",
|
||||||
outname=None,
|
outname=None,
|
||||||
dens=1.0,
|
dens=1.0,
|
||||||
nmol=[1],
|
nmol=[1],
|
||||||
nstep=[1, 1],
|
nstep=[1, 1],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
ex.exception, "Error: 'outname' keyword not specified in config file"
|
assert ex.value == "Error: 'outname' keyword not specified in config file"
|
||||||
)
|
|
||||||
|
|
||||||
def test_validate_dens(self):
|
def test_validate_dens(self):
|
||||||
with self.assertRaises(ValueError) as ex:
|
with pytest.raises(ValueError) as ex:
|
||||||
DiceConfig(
|
DiceConfig(
|
||||||
|
nprocs=1,
|
||||||
ljname="test",
|
ljname="test",
|
||||||
outname="test",
|
outname="test",
|
||||||
dens=None,
|
dens=None,
|
||||||
nmol=[1],
|
nmol=[1],
|
||||||
nstep=[1, 1],
|
nstep=[1, 1],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
ex.exception, "Error: 'dens' keyword not specified in config file"
|
assert ex.value == "Error: 'dens' keyword not specified in config file"
|
||||||
)
|
|
||||||
|
|
||||||
def test_validate_nmol(self):
|
def test_validate_nmol(self):
|
||||||
with self.assertRaises(ValueError) as ex:
|
with pytest.raises(ValueError) as ex:
|
||||||
DiceConfig(
|
DiceConfig(
|
||||||
|
nprocs=1,
|
||||||
ljname="test",
|
ljname="test",
|
||||||
outname="test",
|
outname="test",
|
||||||
dens=1.0,
|
dens=1.0,
|
||||||
nmol=0,
|
nmol=0,
|
||||||
nstep=[1, 1],
|
nstep=[1, 1],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
ex.exception,
|
assert ex.value == "Error: 'nmol' keyword not specified in config file"
|
||||||
"Error: 'nmol' keyword not defined appropriately in config file",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_validate_nstep(self):
|
def test_validate_nstep(self):
|
||||||
with self.assertRaises(ValueError) as ex:
|
with pytest.raises(ValueError) as ex:
|
||||||
DiceConfig(
|
DiceConfig(
|
||||||
|
nprocs=1,
|
||||||
ljname="test",
|
ljname="test",
|
||||||
outname="test",
|
outname="test",
|
||||||
dens=1.0,
|
dens=1.0,
|
||||||
nmol=[1],
|
nmol=[1],
|
||||||
nstep=0,
|
nstep=0,
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
ex.exception,
|
assert ex.value == "Error: 'nstep' keyword not specified in config file"
|
||||||
"Error: 'nstep' keyword not defined appropriately in config file",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_from_dict(self):
|
def test_from_dict(self):
|
||||||
dice_dto = DiceConfig.from_dict(
|
dice_dto = DiceConfig.model_validate(
|
||||||
{
|
{
|
||||||
|
"nprocs": 1,
|
||||||
"ljname": "test",
|
"ljname": "test",
|
||||||
"outname": "test",
|
"outname": "test",
|
||||||
"dens": 1.0,
|
"dens": 1.0,
|
||||||
@@ -93,4 +93,4 @@ class TestDiceDto(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertIsInstance(dice_dto, DiceConfig)
|
assert isinstance(dice_dto, DiceConfig)
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
from diceplayer.shared.config.gaussian_config import GaussianDTO
|
from diceplayer.config.gaussian_config import GaussianConfig
|
||||||
|
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class TestGaussianDTO(unittest.TestCase):
|
class TestGaussianConfig:
|
||||||
def test_class_instantiation(self):
|
def test_class_instantiation(self):
|
||||||
gaussian_dto = GaussianDTO(
|
gaussian_dto = GaussianConfig(
|
||||||
level="test",
|
level="test",
|
||||||
qmprog="g16",
|
qmprog="g16",
|
||||||
keywords="test",
|
keywords="test",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertIsInstance(gaussian_dto, GaussianDTO)
|
assert isinstance(gaussian_dto, GaussianConfig)
|
||||||
|
|
||||||
def test_is_valid_qmprog(self):
|
def test_is_valid_qmprog(self):
|
||||||
with self.assertRaises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
gaussian_dto = GaussianDTO(
|
GaussianConfig(
|
||||||
level="test",
|
level="test",
|
||||||
qmprog="test",
|
qmprog="test",
|
||||||
keywords="test",
|
keywords="test",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_is_valid_level(self):
|
def test_is_valid_level(self):
|
||||||
with self.assertRaises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
gaussian_dto = GaussianDTO(
|
GaussianConfig(
|
||||||
level=None,
|
level=None,
|
||||||
qmprog="g16",
|
qmprog="g16",
|
||||||
keywords="test",
|
keywords="test",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_from_dict(self):
|
def test_from_dict(self):
|
||||||
gaussian_dto = GaussianDTO.from_dict(
|
gaussian_dto = GaussianConfig.model_validate(
|
||||||
{
|
{
|
||||||
"level": "test",
|
"level": "test",
|
||||||
"qmprog": "g16",
|
"qmprog": "g16",
|
||||||
@@ -38,8 +38,4 @@ class TestGaussianDTO(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertIsInstance(gaussian_dto, GaussianDTO)
|
assert isinstance(gaussian_dto, GaussianConfig)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
90
tests/config/test_player_config.py
Normal file
90
tests/config/test_player_config.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
from diceplayer.config.dice_config import DiceConfig
|
||||||
|
from diceplayer.config.gaussian_config import GaussianConfig
|
||||||
|
from diceplayer.config.player_config import PlayerConfig, RoutineType
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class TestPlayerConfig:
|
||||||
|
@pytest.fixture
|
||||||
|
def dice_payload(self) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"nprocs": 4,
|
||||||
|
"ljname": "test",
|
||||||
|
"outname": "test",
|
||||||
|
"dens": 1.0,
|
||||||
|
"nmol": [1],
|
||||||
|
"nstep": [1, 1],
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def gaussian_payload(self) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"level": "test",
|
||||||
|
"qmprog": "g16",
|
||||||
|
"keywords": "test",
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def player_payload(
|
||||||
|
self, dice_payload: dict[str, Any], gaussian_payload: dict[str, Any]
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"type": "both",
|
||||||
|
"mem": 12,
|
||||||
|
"max_cyc": 100,
|
||||||
|
"switch_cyc": 50,
|
||||||
|
"ncores": 4,
|
||||||
|
"dice": dice_payload,
|
||||||
|
"gaussian": gaussian_payload,
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dice_config(self, dice_payload: dict[str, Any]) -> DiceConfig:
|
||||||
|
return DiceConfig.model_validate(dice_payload)
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def gaussian_config(self, gaussian_payload: dict[str, Any]):
|
||||||
|
return GaussianConfig.model_validate(gaussian_payload)
|
||||||
|
|
||||||
|
def test_class_instantiation(
|
||||||
|
self, dice_config: DiceConfig, gaussian_config: GaussianConfig
|
||||||
|
):
|
||||||
|
player_dto = PlayerConfig(
|
||||||
|
type=RoutineType.BOTH,
|
||||||
|
mem=12,
|
||||||
|
max_cyc=100,
|
||||||
|
switch_cyc=50,
|
||||||
|
ncores=4,
|
||||||
|
dice=dice_config,
|
||||||
|
gaussian=gaussian_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert isinstance(player_dto, PlayerConfig)
|
||||||
|
assert isinstance(player_dto.dice, DiceConfig)
|
||||||
|
assert isinstance(player_dto.gaussian, GaussianConfig)
|
||||||
|
|
||||||
|
def test_min_altsteps(
|
||||||
|
self, dice_config: DiceConfig, gaussian_config: GaussianConfig
|
||||||
|
):
|
||||||
|
player_dto = PlayerConfig(
|
||||||
|
type=RoutineType.BOTH,
|
||||||
|
mem=12,
|
||||||
|
max_cyc=100,
|
||||||
|
switch_cyc=50,
|
||||||
|
ncores=4,
|
||||||
|
altsteps=0,
|
||||||
|
dice=dice_config,
|
||||||
|
gaussian=gaussian_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert player_dto.altsteps == 20000
|
||||||
|
|
||||||
|
def test_from_dict(self, player_payload: dict[str, Any]):
|
||||||
|
player_dto = PlayerConfig.model_validate(player_payload)
|
||||||
|
|
||||||
|
assert isinstance(player_dto, PlayerConfig)
|
||||||
|
assert isinstance(player_dto.dice, DiceConfig)
|
||||||
|
assert isinstance(player_dto.gaussian, GaussianConfig)
|
||||||
67
tests/dice/test_dice_input.py
Normal file
67
tests/dice/test_dice_input.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.dice.dice_input import (
|
||||||
|
NPTEqConfig,
|
||||||
|
NPTTerConfig,
|
||||||
|
NVTEqConfig,
|
||||||
|
NVTTerConfig,
|
||||||
|
write_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class TestDiceInput:
|
||||||
|
@pytest.fixture
|
||||||
|
def player_config(self) -> PlayerConfig:
|
||||||
|
return PlayerConfig.model_validate(
|
||||||
|
{
|
||||||
|
"type": "both",
|
||||||
|
"mem": 12,
|
||||||
|
"max_cyc": 100,
|
||||||
|
"switch_cyc": 50,
|
||||||
|
"ncores": 4,
|
||||||
|
"dice": {
|
||||||
|
"nprocs": 4,
|
||||||
|
"ljname": "test",
|
||||||
|
"outname": "test",
|
||||||
|
"dens": 1.0,
|
||||||
|
"nmol": [1],
|
||||||
|
"nstep": [1, 1],
|
||||||
|
},
|
||||||
|
"gaussian": {
|
||||||
|
"level": "test",
|
||||||
|
"qmprog": "g16",
|
||||||
|
"keywords": "test",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_generate_nvt_ter_input(self, player_config: PlayerConfig):
|
||||||
|
dice_input = NVTTerConfig.from_config(player_config)
|
||||||
|
|
||||||
|
assert isinstance(dice_input, NVTTerConfig)
|
||||||
|
|
||||||
|
def test_generate_nvt_eq_input(self, player_config: PlayerConfig):
|
||||||
|
dice_input = NVTEqConfig.from_config(player_config)
|
||||||
|
|
||||||
|
assert isinstance(dice_input, NVTEqConfig)
|
||||||
|
|
||||||
|
def test_generate_npt_ter_input(self, player_config: PlayerConfig):
|
||||||
|
dice_input = NPTTerConfig.from_config(player_config)
|
||||||
|
|
||||||
|
assert isinstance(dice_input, NPTTerConfig)
|
||||||
|
|
||||||
|
def test_generate_npt_eq_input(self, player_config: PlayerConfig):
|
||||||
|
dice_input = NPTEqConfig.from_config(player_config)
|
||||||
|
|
||||||
|
assert isinstance(dice_input, NPTEqConfig)
|
||||||
|
|
||||||
|
def test_write_dice_config(self, player_config: PlayerConfig, tmp_path: Path):
|
||||||
|
dice_input = NVTTerConfig.from_config(player_config)
|
||||||
|
|
||||||
|
output_file = tmp_path / dice_input.type
|
||||||
|
write_config(dice_input, tmp_path)
|
||||||
|
|
||||||
|
assert output_file.exists()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from diceplayer.shared.environment.atom import Atom
|
from diceplayer.environment import Atom
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from diceplayer.shared.environment.atom import Atom
|
from diceplayer.environment import Atom, Molecule
|
||||||
from diceplayer.shared.environment.molecule import Molecule
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.testing as npt
|
import numpy.testing as npt
|
||||||
@@ -42,7 +41,7 @@ class TestMolecule(unittest.TestCase):
|
|||||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
mol.center_of_mass_to_origin()
|
mol.move_center_of_mass_to_origin()
|
||||||
|
|
||||||
npt.assert_equal(mol.com, [0, 0, 0])
|
npt.assert_equal(mol.com, [0, 0, 0])
|
||||||
|
|
||||||
@@ -69,12 +68,10 @@ class TestMolecule(unittest.TestCase):
|
|||||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_distance_between_atoms = [[1.73205081], [1.73205081]]
|
expected = [[0.0, 1.73205081], [1.73205081, 0.0]]
|
||||||
actual_distance_between_atoms = mol.distances_between_atoms()
|
actual = mol.distances_between_atoms()
|
||||||
|
|
||||||
npt.assert_almost_equal(
|
npt.assert_almost_equal(expected, actual)
|
||||||
expected_distance_between_atoms, actual_distance_between_atoms
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_inertia_tensor(self):
|
def test_inertia_tensor(self):
|
||||||
mol = Molecule("test")
|
mol = Molecule("test")
|
||||||
@@ -92,7 +89,7 @@ class TestMolecule(unittest.TestCase):
|
|||||||
[-0.50395, -0.50395, 1.0079],
|
[-0.50395, -0.50395, 1.0079],
|
||||||
]
|
]
|
||||||
|
|
||||||
actual_inertia_tensor = mol.inertia_tensor()
|
actual_inertia_tensor = mol.inertia_tensor
|
||||||
|
|
||||||
npt.assert_equal(expected_inertia_tensor, actual_inertia_tensor)
|
npt.assert_equal(expected_inertia_tensor, actual_inertia_tensor)
|
||||||
|
|
||||||
@@ -103,11 +100,14 @@ class TestMolecule(unittest.TestCase):
|
|||||||
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
Atom(lbl=1, na=1, rx=0.0, ry=0.0, rz=0.0, chg=1.0, eps=1.0, sig=1.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_evals, expected_evecs = [0.0, 0.0, 0.0], [
|
expected_evals, expected_evecs = (
|
||||||
[1.0, 0.0, 0.0],
|
[0.0, 0.0, 0.0],
|
||||||
[0.0, 1.0, 0.0],
|
[
|
||||||
[0.0, 0.0, 1.0],
|
[1.0, 0.0, 0.0],
|
||||||
]
|
[0.0, 1.0, 0.0],
|
||||||
|
[0.0, 0.0, 1.0],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
evals, evecs = mol.principal_axes()
|
evals, evecs = mol.principal_axes()
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ class TestMolecule(unittest.TestCase):
|
|||||||
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
Atom(lbl=1, na=1, rx=1.0, ry=1.0, rz=1.0, chg=1.0, eps=1.0, sig=1.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
mol.standard_orientation()
|
mol.rotate_to_standard_orientation()
|
||||||
|
|
||||||
expected_position = [0.0, 0.0, 0.0]
|
expected_position = [0.0, 0.0, 0.0]
|
||||||
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
from diceplayer.shared.environment.atom import Atom
|
from diceplayer.environment import Molecule, System
|
||||||
from diceplayer.shared.environment.molecule import Molecule
|
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
def get_config_example():
|
|
||||||
return """
|
|
||||||
diceplayer:
|
|
||||||
opt: no
|
|
||||||
mem: 12
|
|
||||||
maxcyc: 3
|
|
||||||
ncores: 4
|
|
||||||
nprocs: 4
|
|
||||||
qmprog: 'g16'
|
|
||||||
lps: no
|
|
||||||
ghosts: no
|
|
||||||
altsteps: 20000
|
|
||||||
|
|
||||||
dice:
|
|
||||||
nmol: [1, 50]
|
|
||||||
dens: 0.75
|
|
||||||
nstep: [2000, 3000, 4000]
|
|
||||||
isave: 1000
|
|
||||||
outname: 'phb'
|
|
||||||
progname: '~/.local/bin/dice'
|
|
||||||
ljname: 'phb.ljc'
|
|
||||||
randominit: 'first'
|
|
||||||
|
|
||||||
gaussian:
|
|
||||||
qmprog: 'g16'
|
|
||||||
level: 'MP2/aug-cc-pVDZ'
|
|
||||||
keywords: 'freq'
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def get_potentials_exemple():
|
|
||||||
return """\
|
|
||||||
*
|
|
||||||
2
|
|
||||||
1 TEST
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
1 PLACEHOLDER
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def get_potentials_error_combrule():
|
|
||||||
return """\
|
|
||||||
.
|
|
||||||
2
|
|
||||||
1 TEST
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
1 PLACEHOLDER
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def get_potentials_error_ntypes():
|
|
||||||
return """\
|
|
||||||
*
|
|
||||||
a
|
|
||||||
1 TEST
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
1 PLACEHOLDER
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def get_potentials_error_ntypes_config():
|
|
||||||
return """\
|
|
||||||
*
|
|
||||||
3
|
|
||||||
1 TEST
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
1 PLACEHOLDER
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def get_potentials_error_nsites():
|
|
||||||
return """\
|
|
||||||
*
|
|
||||||
2
|
|
||||||
. TEST
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
1 PLACEHOLDER
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def get_potentials_error_molname():
|
|
||||||
return """\
|
|
||||||
*
|
|
||||||
2
|
|
||||||
1
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
1 PLACEHOLDER
|
|
||||||
1 1 0.000000 0.000000 0.000000 0.000000 0.0000 0.0000
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def mock_open(file, *args, **kwargs):
|
|
||||||
values = {
|
|
||||||
"control.test.yml": get_config_example(),
|
|
||||||
"phb.ljc": get_potentials_exemple(),
|
|
||||||
"phb.error.combrule.ljc": get_potentials_error_combrule(),
|
|
||||||
"phb.error.ntypes.ljc": get_potentials_error_ntypes(),
|
|
||||||
"phb.error.ntypes.config.ljc": get_potentials_error_ntypes_config(),
|
|
||||||
"phb.error.nsites.ljc": get_potentials_error_nsites(),
|
|
||||||
"phb.error.molname.ljc": get_potentials_error_molname(),
|
|
||||||
}
|
|
||||||
if file in values:
|
|
||||||
return mock.mock_open(read_data=values[file])()
|
|
||||||
|
|
||||||
return mock.mock_open(read_data="")()
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import itertools
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
|
|
||||||
class MockProc:
|
|
||||||
pid_counter = itertools.count()
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.pid = next(MockProc.pid_counter)
|
|
||||||
|
|
||||||
if "exitcode" in kwargs:
|
|
||||||
self.exitcode = kwargs["exitcode"]
|
|
||||||
else:
|
|
||||||
self.exitcode = 0
|
|
||||||
|
|
||||||
self.sentinel = self.pid
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def terminate(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MockConnection:
|
|
||||||
@staticmethod
|
|
||||||
def wait(sentinels: List[int]):
|
|
||||||
return sentinels
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
from diceplayer.shared.config.dice_config import DiceConfig
|
|
||||||
from diceplayer.shared.config.gaussian_config import GaussianDTO
|
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
|
|
||||||
def get_config_dict():
|
|
||||||
return {
|
|
||||||
"opt": True,
|
|
||||||
"mem": 12,
|
|
||||||
"maxcyc": 100,
|
|
||||||
"nprocs": 4,
|
|
||||||
"ncores": 4,
|
|
||||||
"dice": {
|
|
||||||
"ljname": "test",
|
|
||||||
"outname": "test",
|
|
||||||
"dens": 1.0,
|
|
||||||
"nmol": [1],
|
|
||||||
"nstep": [1, 1],
|
|
||||||
},
|
|
||||||
"gaussian": {
|
|
||||||
"level": "test",
|
|
||||||
"qmprog": "g16",
|
|
||||||
"keywords": "test",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class TestPlayerDTO(unittest.TestCase):
|
|
||||||
def setUp(self) -> None:
|
|
||||||
self.dice_dto = DiceConfig(
|
|
||||||
ljname="test",
|
|
||||||
outname="test",
|
|
||||||
dens=1.0,
|
|
||||||
nmol=[1],
|
|
||||||
nstep=[1, 1],
|
|
||||||
)
|
|
||||||
self.gaussian_dto = GaussianDTO(
|
|
||||||
level="test",
|
|
||||||
qmprog="g16",
|
|
||||||
keywords="test",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_class_instantiation(self):
|
|
||||||
player_dto = PlayerConfig(
|
|
||||||
opt=True,
|
|
||||||
mem=12,
|
|
||||||
maxcyc=100,
|
|
||||||
nprocs=4,
|
|
||||||
ncores=4,
|
|
||||||
dice=self.dice_dto,
|
|
||||||
gaussian=self.gaussian_dto,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertIsInstance(player_dto, PlayerConfig)
|
|
||||||
self.assertIsInstance(player_dto.dice, DiceConfig)
|
|
||||||
self.assertIsInstance(player_dto.gaussian, GaussianDTO)
|
|
||||||
|
|
||||||
def test_min_altsteps(self):
|
|
||||||
player_dto = PlayerConfig(
|
|
||||||
opt=True,
|
|
||||||
mem=12,
|
|
||||||
maxcyc=100,
|
|
||||||
nprocs=4,
|
|
||||||
ncores=4,
|
|
||||||
altsteps=100,
|
|
||||||
dice=self.dice_dto,
|
|
||||||
gaussian=self.gaussian_dto,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(player_dto.altsteps, 20000)
|
|
||||||
|
|
||||||
def test_from_dict(self):
|
|
||||||
player_dto = PlayerConfig.from_dict(get_config_dict())
|
|
||||||
|
|
||||||
self.assertIsInstance(player_dto, PlayerConfig)
|
|
||||||
self.assertIsInstance(player_dto.dice, DiceConfig)
|
|
||||||
self.assertIsInstance(player_dto.gaussian, GaussianDTO)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
@@ -1,661 +0,0 @@
|
|||||||
from diceplayer import logger
|
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
|
||||||
from diceplayer.shared.environment.atom import Atom
|
|
||||||
from diceplayer.shared.environment.molecule import Molecule
|
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
from diceplayer.shared.interface.dice_interface import DiceInterface
|
|
||||||
from tests.mocks.mock_inputs import get_config_example
|
|
||||||
from tests.mocks.mock_proc import MockConnection, MockProc
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
import io
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestDiceInterface(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
config = yaml.load(get_config_example(), Loader=yaml.Loader)
|
|
||||||
self.config = PlayerConfig.from_dict(config["diceplayer"])
|
|
||||||
|
|
||||||
def test_class_instantiation(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
|
|
||||||
self.assertIsInstance(dice, DiceInterface)
|
|
||||||
|
|
||||||
def test_configure(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
|
|
||||||
self.assertIsNone(dice.step)
|
|
||||||
self.assertIsNone(dice.system)
|
|
||||||
|
|
||||||
# Ignoring the types for testing purposes
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
self.assertIsNotNone(dice.step)
|
|
||||||
self.assertIsNotNone(dice.system)
|
|
||||||
|
|
||||||
def test_reset(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
self.assertTrue(hasattr(dice, "step"))
|
|
||||||
self.assertTrue(hasattr(dice, "system"))
|
|
||||||
|
|
||||||
dice.reset()
|
|
||||||
|
|
||||||
self.assertFalse(hasattr(dice, "step"))
|
|
||||||
self.assertFalse(hasattr(dice, "system"))
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.Process", MockProc())
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.connection", MockConnection)
|
|
||||||
def test_start(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.start(1)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.connection", MockConnection)
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.Process", MockProc(exitcode=1)
|
|
||||||
)
|
|
||||||
def test_start_with_process_error(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
with self.assertRaises(SystemExit):
|
|
||||||
dice.start(1)
|
|
||||||
|
|
||||||
def test_simulation_process_raises_exception(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
|
|
||||||
with self.assertRaises(SystemExit):
|
|
||||||
dice._simulation_process(1, 1)
|
|
||||||
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.DiceInterface._make_proc_dir"
|
|
||||||
)
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.DiceInterface._make_dice_inputs"
|
|
||||||
)
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.DiceInterface._run_dice")
|
|
||||||
def test_simulation_process(
|
|
||||||
self, mock_run_dice, mock_make_dice_inputs, mock_make_proc_dir
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
|
|
||||||
dice._simulation_process(1, 1)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_proc_dir.called)
|
|
||||||
self.assertTrue(dice._make_dice_inputs.called)
|
|
||||||
self.assertTrue(dice._run_dice.called)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.mkdir")
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.exists")
|
|
||||||
def test_make_proc_dir_if_simdir_exists(self, mock_path_exists, mock_path_mkdir):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
mock_path_exists.return_value = False
|
|
||||||
|
|
||||||
dice._make_proc_dir(1, 1)
|
|
||||||
|
|
||||||
self.assertEqual(mock_path_mkdir.call_count, 2)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.mkdir")
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.Path.exists")
|
|
||||||
def test_make_proc_dir_if_simdir_doesnt_exists(
|
|
||||||
self, mock_path_exists, mock_path_mkdir
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
mock_path_exists.return_value = False
|
|
||||||
|
|
||||||
dice._make_proc_dir(1, 1)
|
|
||||||
|
|
||||||
self.assertEqual(mock_path_mkdir.call_count, 2)
|
|
||||||
|
|
||||||
def test_make_dice_seed(self):
|
|
||||||
seed = DiceInterface._make_dice_seed()
|
|
||||||
|
|
||||||
self.assertIsInstance(seed, int)
|
|
||||||
|
|
||||||
def test_make_dice_inputs_nstep_len_two_with_randoninit_first_cycle_one(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.step.dice.nstep = [1, 1]
|
|
||||||
|
|
||||||
dice._make_potentials = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_init_file = mock.Mock()
|
|
||||||
dice._new_density = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_nvt_ter = mock.Mock()
|
|
||||||
dice._make_nvt_eq = mock.Mock()
|
|
||||||
dice._make_npt_ter = mock.Mock()
|
|
||||||
dice._make_npt_eq = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_dice_inputs(1, 1)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_potentials.called)
|
|
||||||
|
|
||||||
self.assertFalse(dice._make_init_file.called)
|
|
||||||
self.assertFalse(dice._new_density.called)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_nvt_ter.called)
|
|
||||||
self.assertTrue(dice._make_nvt_eq.called)
|
|
||||||
|
|
||||||
self.assertFalse(dice._make_npt_ter.called)
|
|
||||||
self.assertFalse(dice._make_npt_eq.called)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open, read_data="test")
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=True
|
|
||||||
)
|
|
||||||
def test_make_dice_inputs_nstep_len_two_with_randoninit_first_cycle_two(
|
|
||||||
self, mock_path_exists, mock_open
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.step.dice.nstep = [1, 1]
|
|
||||||
|
|
||||||
dice._make_potentials = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_init_file = mock.Mock()
|
|
||||||
dice._new_density = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_nvt_ter = mock.Mock()
|
|
||||||
dice._make_nvt_eq = mock.Mock()
|
|
||||||
dice._make_npt_ter = mock.Mock()
|
|
||||||
dice._make_npt_eq = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_dice_inputs(2, 1)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_potentials.called)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_init_file.called)
|
|
||||||
self.assertTrue(dice._new_density.called)
|
|
||||||
|
|
||||||
self.assertFalse(dice._make_nvt_ter.called)
|
|
||||||
self.assertTrue(dice._make_nvt_eq.called)
|
|
||||||
|
|
||||||
self.assertFalse(dice._make_npt_ter.called)
|
|
||||||
self.assertFalse(dice._make_npt_eq.called)
|
|
||||||
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=False
|
|
||||||
)
|
|
||||||
def test_make_dice_inputs_raises_exception_on_last_not_found(
|
|
||||||
self, mock_path_exists
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.step.dice.nstep = [1, 1]
|
|
||||||
|
|
||||||
dice._make_potentials = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_init_file = mock.Mock()
|
|
||||||
dice._new_density = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_nvt_ter = mock.Mock()
|
|
||||||
dice._make_nvt_eq = mock.Mock()
|
|
||||||
dice._make_npt_ter = mock.Mock()
|
|
||||||
dice._make_npt_eq = mock.Mock()
|
|
||||||
|
|
||||||
with self.assertRaises(FileNotFoundError):
|
|
||||||
dice._make_dice_inputs(2, 1)
|
|
||||||
|
|
||||||
def test_make_dice_inputs_nstep_len_three_with_randoninit_first_cycle_one(self):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice._make_potentials = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_init_file = mock.Mock()
|
|
||||||
dice._new_density = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_nvt_ter = mock.Mock()
|
|
||||||
dice._make_nvt_eq = mock.Mock()
|
|
||||||
dice._make_npt_ter = mock.Mock()
|
|
||||||
dice._make_npt_eq = mock.Mock()
|
|
||||||
|
|
||||||
dice._make_dice_inputs(1, 1)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_potentials.called)
|
|
||||||
|
|
||||||
self.assertFalse(dice._make_init_file.called)
|
|
||||||
self.assertFalse(dice._new_density.called)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_nvt_ter.called)
|
|
||||||
self.assertFalse(dice._make_nvt_eq.called)
|
|
||||||
|
|
||||||
self.assertTrue(dice._make_npt_ter.called)
|
|
||||||
self.assertTrue(dice._make_npt_eq.called)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.os")
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.shutil")
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=True
|
|
||||||
)
|
|
||||||
def test_run_dice_on_first_cycle_run_successful(
|
|
||||||
self, mock_path_exists, mock_shutils, mock_os
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.step.dice.nstep = [1, 1, 1]
|
|
||||||
|
|
||||||
dice.run_dice_file = mock.Mock()
|
|
||||||
|
|
||||||
dice._run_dice(1, 1)
|
|
||||||
|
|
||||||
self.assertTrue(mock_os.getcwd.called)
|
|
||||||
self.assertTrue(mock_os.chdir.called)
|
|
||||||
|
|
||||||
self.assertEqual(dice.run_dice_file.call_count, 3)
|
|
||||||
self.assertTrue(mock_shutils.copy.called)
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.step.dice.nstep = [1, 1]
|
|
||||||
|
|
||||||
dice.run_dice_file = mock.Mock()
|
|
||||||
|
|
||||||
dice._run_dice(1, 1)
|
|
||||||
|
|
||||||
self.assertTrue(mock_os.getcwd.called)
|
|
||||||
self.assertTrue(mock_os.chdir.called)
|
|
||||||
|
|
||||||
self.assertEqual(dice.run_dice_file.call_count, 2)
|
|
||||||
self.assertTrue(mock_shutils.copy.called)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.os")
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.shutil")
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=True
|
|
||||||
)
|
|
||||||
def test_run_dice_on_second_cycle_run_successful(
|
|
||||||
self, mock_path_exists, mock_shutils, mock_os
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.run_dice_file = mock.Mock()
|
|
||||||
|
|
||||||
dice._run_dice(2, 1)
|
|
||||||
|
|
||||||
self.assertTrue(mock_os.getcwd.called)
|
|
||||||
self.assertTrue(mock_os.chdir.called)
|
|
||||||
|
|
||||||
self.assertEqual(dice.run_dice_file.call_count, 2)
|
|
||||||
self.assertTrue(mock_shutils.copy.called)
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.run_dice_file = mock.Mock()
|
|
||||||
|
|
||||||
dice._run_dice(2, 1)
|
|
||||||
|
|
||||||
self.assertTrue(mock_os.getcwd.called)
|
|
||||||
self.assertTrue(mock_os.chdir.called)
|
|
||||||
|
|
||||||
self.assertEqual(dice.run_dice_file.call_count, 1)
|
|
||||||
self.assertTrue(mock_shutils.copy.called)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.os")
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.shutil")
|
|
||||||
@mock.patch(
|
|
||||||
"diceplayer.shared.interface.dice_interface.Path.exists", return_value=False
|
|
||||||
)
|
|
||||||
def test_run_dice_on_second_cycle_run_successful(
|
|
||||||
self, mock_path_exists, mock_shutils, mock_os
|
|
||||||
):
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.run_dice_file = mock.Mock()
|
|
||||||
|
|
||||||
with self.assertRaises(FileNotFoundError):
|
|
||||||
dice._run_dice(1, 1)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
def test_make_init_file(self, mock_open):
|
|
||||||
example_atom = Atom(
|
|
||||||
lbl=1,
|
|
||||||
na=1,
|
|
||||||
rx=1.0,
|
|
||||||
ry=1.0,
|
|
||||||
rz=1.0,
|
|
||||||
chg=1.0,
|
|
||||||
eps=1.0,
|
|
||||||
sig=1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
main_molecule = Molecule("main_molecule")
|
|
||||||
main_molecule.add_atom(example_atom)
|
|
||||||
|
|
||||||
secondary_molecule = Molecule("secondary_molecule")
|
|
||||||
secondary_molecule.add_atom(example_atom)
|
|
||||||
|
|
||||||
system = System()
|
|
||||||
system.add_type(main_molecule)
|
|
||||||
system.add_type(secondary_molecule)
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, system)
|
|
||||||
|
|
||||||
dice.step.dice.nmol = [1, 1]
|
|
||||||
|
|
||||||
last_xyz_file = io.StringIO()
|
|
||||||
last_xyz_file.writelines(
|
|
||||||
[
|
|
||||||
" TEST\n",
|
|
||||||
" Configuration number : TEST = TEST TEST TEST\n",
|
|
||||||
" H 1.00000 1.00000 1.00000\n",
|
|
||||||
" H 1.00000 1.00000 1.00000\n",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
last_xyz_file.seek(0)
|
|
||||||
|
|
||||||
dice._make_init_file("test", last_xyz_file)
|
|
||||||
|
|
||||||
mock_handler = mock_open()
|
|
||||||
calls = mock_handler.write.call_args_list
|
|
||||||
|
|
||||||
lines = list(map(lambda x: x[0][0], calls))
|
|
||||||
|
|
||||||
expected_lines = [
|
|
||||||
" 1.000000 1.000000 1.000000\n",
|
|
||||||
" 1.000000 1.000000 1.000000\n",
|
|
||||||
"$end",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(lines, expected_lines)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
def test_new_density(self, mock_open):
|
|
||||||
example_atom = Atom(
|
|
||||||
lbl=1,
|
|
||||||
na=1,
|
|
||||||
rx=1.0,
|
|
||||||
ry=1.0,
|
|
||||||
rz=1.0,
|
|
||||||
chg=1.0,
|
|
||||||
eps=1.0,
|
|
||||||
sig=1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
main_molecule = Molecule("main_molecule")
|
|
||||||
main_molecule.add_atom(example_atom)
|
|
||||||
|
|
||||||
secondary_molecule = Molecule("secondary_molecule")
|
|
||||||
secondary_molecule.add_atom(example_atom)
|
|
||||||
|
|
||||||
system = System()
|
|
||||||
system.add_type(main_molecule)
|
|
||||||
system.add_type(secondary_molecule)
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, system)
|
|
||||||
|
|
||||||
last_xyz_file = io.StringIO()
|
|
||||||
last_xyz_file.writelines(
|
|
||||||
[
|
|
||||||
" TEST\n",
|
|
||||||
" Configuration number : TEST = 1 1 1\n",
|
|
||||||
" H 1.00000 1.00000 1.00000\n",
|
|
||||||
" H 1.00000 1.00000 1.00000\n",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
last_xyz_file.seek(0)
|
|
||||||
|
|
||||||
density = dice._new_density(last_xyz_file)
|
|
||||||
|
|
||||||
self.assertEqual(density, 85.35451545000001)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
|
||||||
def test_make_nvt_ter(self, mock_random, mock_open):
|
|
||||||
mock_random.random.return_value = 1
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice._make_nvt_ter(1, "test")
|
|
||||||
|
|
||||||
mock_handler = mock_open()
|
|
||||||
calls = mock_handler.write.call_args_list
|
|
||||||
|
|
||||||
lines = list(map(lambda x: x[0][0], calls))
|
|
||||||
|
|
||||||
expected_lines = [
|
|
||||||
"title = Diceplayer run - NVT Thermalization\n",
|
|
||||||
"ncores = 4\n",
|
|
||||||
"ljname = phb.ljc\n",
|
|
||||||
"outname = phb\n",
|
|
||||||
"nmol = 1 50\n",
|
|
||||||
"dens = 0.75\n",
|
|
||||||
"temp = 300.0\n",
|
|
||||||
"init = yes\n",
|
|
||||||
"nstep = 2000\n",
|
|
||||||
"vstep = 0\n",
|
|
||||||
"mstop = 1\n",
|
|
||||||
"accum = no\n",
|
|
||||||
"iprint = 1\n",
|
|
||||||
"isave = 0\n",
|
|
||||||
"irdf = 0\n",
|
|
||||||
"seed = 1000000\n",
|
|
||||||
"upbuf = 360",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(lines, expected_lines)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
|
||||||
def test_make_nvt_eq(self, mock_random, mock_open):
|
|
||||||
mock_random.random.return_value = 1
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice._make_nvt_eq(1, "test")
|
|
||||||
|
|
||||||
mock_handler = mock_open()
|
|
||||||
calls = mock_handler.write.call_args_list
|
|
||||||
|
|
||||||
lines = list(map(lambda x: x[0][0], calls))
|
|
||||||
|
|
||||||
expected_lines = [
|
|
||||||
"title = Diceplayer run - NVT Production\n",
|
|
||||||
"ncores = 4\n",
|
|
||||||
"ljname = phb.ljc\n",
|
|
||||||
"outname = phb\n",
|
|
||||||
"nmol = 1 50\n",
|
|
||||||
"dens = 0.75\n",
|
|
||||||
"temp = 300.0\n",
|
|
||||||
"init = no\n",
|
|
||||||
"nstep = 3000\n",
|
|
||||||
"vstep = 0\n",
|
|
||||||
"mstop = 1\n",
|
|
||||||
"accum = no\n",
|
|
||||||
"iprint = 1\n",
|
|
||||||
"isave = 1000\n",
|
|
||||||
"irdf = 40\n",
|
|
||||||
"seed = 1000000\n",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(lines, expected_lines)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
|
||||||
def test_make_npt_ter(self, mock_random, mock_open):
|
|
||||||
mock_random.random.return_value = 1
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice._make_npt_ter(1, "test")
|
|
||||||
|
|
||||||
mock_handler = mock_open()
|
|
||||||
calls = mock_handler.write.call_args_list
|
|
||||||
|
|
||||||
lines = list(map(lambda x: x[0][0], calls))
|
|
||||||
|
|
||||||
expected_lines = [
|
|
||||||
"title = Diceplayer run - NPT Thermalization\n",
|
|
||||||
"ncores = 4\n",
|
|
||||||
"ljname = phb.ljc\n",
|
|
||||||
"outname = phb\n",
|
|
||||||
"nmol = 1 50\n",
|
|
||||||
"press = 1.0\n",
|
|
||||||
"temp = 300.0\n",
|
|
||||||
"init = no\n",
|
|
||||||
"vstep = 600\n",
|
|
||||||
"nstep = 5\n",
|
|
||||||
"mstop = 1\n",
|
|
||||||
"accum = no\n",
|
|
||||||
"iprint = 1\n",
|
|
||||||
"isave = 0\n",
|
|
||||||
"irdf = 0\n",
|
|
||||||
"seed = 1000000\n",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(lines, expected_lines)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.random")
|
|
||||||
def test_make_npt_eq(self, mock_random, mock_open):
|
|
||||||
mock_random.random.return_value = 1
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice._make_npt_eq("test")
|
|
||||||
|
|
||||||
mock_handler = mock_open()
|
|
||||||
calls = mock_handler.write.call_args_list
|
|
||||||
|
|
||||||
lines = list(map(lambda x: x[0][0], calls))
|
|
||||||
|
|
||||||
expected_lines = [
|
|
||||||
"title = Diceplayer run - NPT Production\n",
|
|
||||||
"ncores = 4\n",
|
|
||||||
"ljname = phb.ljc\n",
|
|
||||||
"outname = phb\n",
|
|
||||||
"nmol = 1 50\n",
|
|
||||||
"press = 1.0\n",
|
|
||||||
"temp = 300.0\n",
|
|
||||||
"nstep = 5\n",
|
|
||||||
"vstep = 800\n",
|
|
||||||
"init = no\n",
|
|
||||||
"mstop = 1\n",
|
|
||||||
"accum = no\n",
|
|
||||||
"iprint = 1\n",
|
|
||||||
"isave = 1000\n",
|
|
||||||
"irdf = 40\n",
|
|
||||||
"seed = 1000000\n",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(lines, expected_lines)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open)
|
|
||||||
def test_make_potentials(self, mock_open):
|
|
||||||
example_atom = Atom(
|
|
||||||
lbl=1,
|
|
||||||
na=1,
|
|
||||||
rx=1.0,
|
|
||||||
ry=1.0,
|
|
||||||
rz=1.0,
|
|
||||||
chg=1.0,
|
|
||||||
eps=1.0,
|
|
||||||
sig=1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
main_molecule = Molecule("main_molecule")
|
|
||||||
main_molecule.add_atom(example_atom)
|
|
||||||
|
|
||||||
secondary_molecule = Molecule("secondary_molecule")
|
|
||||||
secondary_molecule.add_atom(example_atom)
|
|
||||||
|
|
||||||
system = System()
|
|
||||||
system.add_type(main_molecule)
|
|
||||||
system.add_type(secondary_molecule)
|
|
||||||
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, system)
|
|
||||||
|
|
||||||
dice._make_potentials("test")
|
|
||||||
|
|
||||||
mock_handler = mock_open()
|
|
||||||
calls = mock_handler.write.call_args_list
|
|
||||||
|
|
||||||
lines = list(map(lambda x: x[0][0], calls))
|
|
||||||
|
|
||||||
expected_lines = [
|
|
||||||
"*\n",
|
|
||||||
"2\n",
|
|
||||||
"1 main_molecule\n",
|
|
||||||
"1 1 1.00000 1.00000 1.00000 1.000000 1.00000 1.0000\n",
|
|
||||||
"1 secondary_molecule\n",
|
|
||||||
"1 1 1.00000 1.00000 1.00000 1.000000 1.00000 1.0000\n",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(lines, expected_lines)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.subprocess")
|
|
||||||
@mock.patch(
|
|
||||||
"builtins.open",
|
|
||||||
new_callable=mock.mock_open,
|
|
||||||
read_data="End of simulation\nBLABLA",
|
|
||||||
)
|
|
||||||
def test_run_dice_file(self, mock_open, mock_subprocess):
|
|
||||||
mock_subprocess.call.return_value = 0
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
dice.run_dice_file(1, 1, "test")
|
|
||||||
|
|
||||||
self.assertTrue(mock_subprocess.call.called)
|
|
||||||
self.assertTrue(mock_open.called)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.subprocess")
|
|
||||||
@mock.patch("builtins.open", new_callable=mock.mock_open, read_data="Error\nBLABLA")
|
|
||||||
def test_run_dice_file_raises_runtime_error_on_dice_file(
|
|
||||||
self, mock_open, mock_subprocess
|
|
||||||
):
|
|
||||||
mock_subprocess.call.return_value = 0
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
with self.assertRaises(RuntimeError):
|
|
||||||
dice.run_dice_file(1, 1, "test")
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.dice_interface.subprocess")
|
|
||||||
@mock.patch(
|
|
||||||
"builtins.open",
|
|
||||||
new_callable=mock.mock_open,
|
|
||||||
read_data="End of simulation\nBLABLA",
|
|
||||||
)
|
|
||||||
def test_run_dice_file_raises_runtime_error_of_dice_exit_code(
|
|
||||||
self, mock_open, mock_subprocess
|
|
||||||
):
|
|
||||||
mock_subprocess.call.return_value = 1
|
|
||||||
dice = DiceInterface()
|
|
||||||
dice.configure(self.config, System())
|
|
||||||
|
|
||||||
with self.assertRaises(RuntimeError):
|
|
||||||
dice.run_dice_file(1, 1, "test")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
from diceplayer import logger
|
|
||||||
from diceplayer.shared.config.player_config import PlayerConfig
|
|
||||||
from diceplayer.shared.environment.system import System
|
|
||||||
from diceplayer.shared.interface.gaussian_interface import GaussianInterface
|
|
||||||
from tests.mocks.mock_inputs import get_config_example
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
import io
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestGaussianInterface(unittest.TestCase):
|
|
||||||
def setUp(self) -> None:
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
config = yaml.load(get_config_example(), Loader=yaml.Loader)
|
|
||||||
self.config = PlayerConfig.from_dict(config["diceplayer"])
|
|
||||||
|
|
||||||
def test_class_instantiation(self):
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
self.assertIsInstance(gaussian_interface, GaussianInterface)
|
|
||||||
|
|
||||||
def test_configure(self):
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
|
|
||||||
self.assertIsNone(gaussian_interface.step)
|
|
||||||
self.assertIsNone(gaussian_interface.system)
|
|
||||||
|
|
||||||
gaussian_interface.configure(self.config, System())
|
|
||||||
|
|
||||||
self.assertIsNotNone(gaussian_interface.step)
|
|
||||||
self.assertIsNotNone(gaussian_interface.system)
|
|
||||||
|
|
||||||
def test_reset(self):
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
|
|
||||||
gaussian_interface.configure(self.config, System())
|
|
||||||
|
|
||||||
self.assertIsNotNone(gaussian_interface.step)
|
|
||||||
self.assertIsNotNone(gaussian_interface.system)
|
|
||||||
|
|
||||||
gaussian_interface.reset()
|
|
||||||
|
|
||||||
self.assertFalse(hasattr(gaussian_interface, "step"))
|
|
||||||
self.assertFalse(hasattr(gaussian_interface, "system"))
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.mkdir")
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
|
||||||
def test_make_qm_dir(self, mock_exists, mock_mkdir):
|
|
||||||
mock_exists.return_value = False
|
|
||||||
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
gaussian_interface.configure(self.config, System())
|
|
||||||
|
|
||||||
gaussian_interface._make_qm_dir(1)
|
|
||||||
|
|
||||||
mock_exists.assert_called_once()
|
|
||||||
mock_mkdir.assert_called_once()
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy")
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
|
||||||
def test_copy_chk_file_from_previous_step(self, mock_exists, mock_copy):
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
gaussian_interface.configure(self.config, System())
|
|
||||||
|
|
||||||
mock_exists.side_effect = [False, True]
|
|
||||||
|
|
||||||
gaussian_interface._copy_chk_file_from_previous_step(2)
|
|
||||||
|
|
||||||
self.assertTrue(mock_exists.called)
|
|
||||||
self.assertTrue(mock_copy.called)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy")
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
|
||||||
def test_copy_chk_file_from_previous_step_no_previous_step(
|
|
||||||
self, mock_exists, mock_copy
|
|
||||||
):
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
gaussian_interface.configure(self.config, System())
|
|
||||||
|
|
||||||
mock_exists.side_effect = [False, False]
|
|
||||||
|
|
||||||
with self.assertRaises(FileNotFoundError):
|
|
||||||
gaussian_interface._copy_chk_file_from_previous_step(2)
|
|
||||||
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.shutil.copy")
|
|
||||||
@mock.patch("diceplayer.shared.interface.gaussian_interface.Path.exists")
|
|
||||||
def test_copy_chk_file_from_previous_step_current_exists(
|
|
||||||
self, mock_exists, mock_copy
|
|
||||||
):
|
|
||||||
gaussian_interface = GaussianInterface()
|
|
||||||
gaussian_interface.configure(self.config, System())
|
|
||||||
|
|
||||||
mock_exists.side_effect = [True, True]
|
|
||||||
|
|
||||||
with self.assertRaises(FileExistsError):
|
|
||||||
gaussian_interface._copy_chk_file_from_previous_step(2)
|
|
||||||
|
|
||||||
# def test_start(self):
|
|
||||||
# gaussian_interface = GaussianInterface()
|
|
||||||
# gaussian_interface.configure(self.config, System())
|
|
||||||
#
|
|
||||||
# gaussian_interface._make_qm_dir = mock.Mock()
|
|
||||||
# gaussian_interface._copy_chk_file_from_previous_step = mock.Mock()
|
|
||||||
#
|
|
||||||
# gaussian_interface.start(2)
|
|
||||||
#
|
|
||||||
# gaussian_interface._make_qm_dir.assert_called_once_with(2)
|
|
||||||
# gaussian_interface._copy_chk_file_from_previous_step.assert_called_once_with(2)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
from diceplayer.shared.utils.logger import Logger, valid_logger
|
|
||||||
|
|
||||||
import io
|
|
||||||
import logging
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestValidateLogger(unittest.TestCase):
|
|
||||||
def test_validate_logger(self):
|
|
||||||
class MockLogger:
|
|
||||||
_was_set = True
|
|
||||||
|
|
||||||
@valid_logger
|
|
||||||
def test_func(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
MockLogger().test_func()
|
|
||||||
|
|
||||||
def test_validate_logger_exception(self):
|
|
||||||
class MockLogger:
|
|
||||||
_was_set = False
|
|
||||||
|
|
||||||
@valid_logger
|
|
||||||
def test_func(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
with self.assertRaises(AssertionError):
|
|
||||||
MockLogger().test_func()
|
|
||||||
|
|
||||||
|
|
||||||
class TestLogger(unittest.TestCase):
|
|
||||||
def test_class_instantiation(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
|
|
||||||
self.assertIsInstance(logger, Logger)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
def test_set_logger_to_file(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
self.assertIsNotNone(logger._logger)
|
|
||||||
self.assertEqual(logger._logger.name, "test")
|
|
||||||
|
|
||||||
def test_set_logger_to_stream(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
self.assertIsNotNone(logger._logger)
|
|
||||||
self.assertEqual(logger._logger.name, "test")
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
@mock.patch("diceplayer.shared.utils.logger.Path.exists")
|
|
||||||
@mock.patch("diceplayer.shared.utils.logger.Path.rename")
|
|
||||||
def test_set_logger_if_file_exists(self, mock_rename, mock_exists):
|
|
||||||
logger = Logger("test")
|
|
||||||
|
|
||||||
mock_exists.return_value = True
|
|
||||||
logger.set_logger()
|
|
||||||
|
|
||||||
self.assertTrue(mock_rename.called)
|
|
||||||
self.assertIsNotNone(logger._logger)
|
|
||||||
self.assertEqual(logger._logger.name, "test")
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
@mock.patch("diceplayer.shared.utils.logger.Path.exists")
|
|
||||||
@mock.patch("diceplayer.shared.utils.logger.Path.rename")
|
|
||||||
def test_set_logger_if_file_not_exists(self, mock_rename, mock_exists):
|
|
||||||
logger = Logger("test")
|
|
||||||
|
|
||||||
mock_exists.return_value = False
|
|
||||||
logger.set_logger()
|
|
||||||
|
|
||||||
self.assertFalse(mock_rename.called)
|
|
||||||
self.assertIsNotNone(logger._logger)
|
|
||||||
self.assertEqual(logger._logger.name, "test")
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
def test_close(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
|
|
||||||
logger.set_logger()
|
|
||||||
logger.close()
|
|
||||||
|
|
||||||
self.assertEqual(len(logger._logger.handlers), 0)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
def test_info(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
with self.assertLogs(level="INFO") as cm:
|
|
||||||
logger.info("test")
|
|
||||||
|
|
||||||
self.assertEqual(cm.output, ["INFO:test:test"])
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
def test_debug(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
logger.set_logger(stream=io.StringIO(), level=logging.DEBUG)
|
|
||||||
|
|
||||||
with self.assertLogs(level="DEBUG") as cm:
|
|
||||||
logger.debug("test")
|
|
||||||
|
|
||||||
self.assertEqual(cm.output, ["DEBUG:test:test"])
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
def test_warning(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
with self.assertLogs(level="WARNING") as cm:
|
|
||||||
logger.warning("test")
|
|
||||||
|
|
||||||
self.assertEqual(cm.output, ["WARNING:test:test"])
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock.mock_open())
|
|
||||||
def test_error(self):
|
|
||||||
logger = Logger("test")
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
with self.assertLogs(level="ERROR") as cm:
|
|
||||||
logger.error("test")
|
|
||||||
|
|
||||||
self.assertEqual(cm.output, ["ERROR:test:test"])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
118
tests/state/test_state_handler.py
Normal file
118
tests/state/test_state_handler.py
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
from diceplayer.config import DiceConfig, GaussianConfig, PlayerConfig
|
||||||
|
from diceplayer.environment import System
|
||||||
|
from diceplayer.state.state_handler import StateHandler
|
||||||
|
from diceplayer.state.state_model import StateModel
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class TestStateHandler:
|
||||||
|
@pytest.fixture
|
||||||
|
def player_config(self) -> PlayerConfig:
|
||||||
|
return PlayerConfig(
|
||||||
|
type="both",
|
||||||
|
mem=12,
|
||||||
|
max_cyc=100,
|
||||||
|
switch_cyc=50,
|
||||||
|
ncores=4,
|
||||||
|
dice=DiceConfig(
|
||||||
|
nprocs=4,
|
||||||
|
ljname="test",
|
||||||
|
outname="test",
|
||||||
|
dens=1.0,
|
||||||
|
nmol=[1],
|
||||||
|
nstep=[1, 1],
|
||||||
|
),
|
||||||
|
gaussian=GaussianConfig(
|
||||||
|
level="test",
|
||||||
|
qmprog="g16",
|
||||||
|
keywords="test",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_initialization(self, tmp_path: Path):
|
||||||
|
state_handler = StateHandler(tmp_path)
|
||||||
|
|
||||||
|
assert isinstance(state_handler, StateHandler)
|
||||||
|
|
||||||
|
def test_save(self, tmp_path: Path, player_config: PlayerConfig):
|
||||||
|
state_handler = StateHandler(tmp_path)
|
||||||
|
|
||||||
|
state = StateModel(
|
||||||
|
config=player_config,
|
||||||
|
system=System(),
|
||||||
|
current_cycle=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
state_handler.save(state)
|
||||||
|
|
||||||
|
assert (tmp_path / "state.pkl").exists()
|
||||||
|
|
||||||
|
def test_get_when_empty(self, tmp_path: Path, player_config: PlayerConfig):
|
||||||
|
state_handler = StateHandler(tmp_path)
|
||||||
|
|
||||||
|
state = state_handler.get(player_config)
|
||||||
|
|
||||||
|
assert state is None
|
||||||
|
|
||||||
|
def test_get(self, tmp_path: Path, player_config: PlayerConfig):
|
||||||
|
state_handler = StateHandler(tmp_path)
|
||||||
|
|
||||||
|
state = StateModel(
|
||||||
|
config=player_config,
|
||||||
|
system=System(),
|
||||||
|
current_cycle=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
state_handler.save(state)
|
||||||
|
|
||||||
|
retrieved_state = state_handler.get(player_config)
|
||||||
|
|
||||||
|
assert retrieved_state is not None
|
||||||
|
assert retrieved_state.config == state.config
|
||||||
|
assert retrieved_state.system == state.system
|
||||||
|
assert retrieved_state.current_cycle == state.current_cycle
|
||||||
|
|
||||||
|
def test_get_with_different_config(
|
||||||
|
self, tmp_path: Path, player_config: PlayerConfig
|
||||||
|
):
|
||||||
|
state_handler = StateHandler(tmp_path)
|
||||||
|
|
||||||
|
state = StateModel(
|
||||||
|
config=player_config,
|
||||||
|
system=System(),
|
||||||
|
current_cycle=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
state_handler.save(state)
|
||||||
|
|
||||||
|
different_config = player_config.model_copy(update={"max_cyc": 200})
|
||||||
|
|
||||||
|
retrieved_state = state_handler.get(different_config)
|
||||||
|
|
||||||
|
assert retrieved_state is None
|
||||||
|
|
||||||
|
def test_get_with_different_config_force(
|
||||||
|
self, tmp_path: Path, player_config: PlayerConfig
|
||||||
|
):
|
||||||
|
state_handler = StateHandler(tmp_path)
|
||||||
|
|
||||||
|
state = StateModel(
|
||||||
|
config=player_config,
|
||||||
|
system=System(),
|
||||||
|
current_cycle=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
state_handler.save(state)
|
||||||
|
|
||||||
|
different_config = player_config.model_copy(update={"max_cyc": 200})
|
||||||
|
|
||||||
|
retrieved_state = state_handler.get(different_config, force=True)
|
||||||
|
|
||||||
|
assert retrieved_state is not None
|
||||||
|
assert retrieved_state.config == state.config
|
||||||
|
assert retrieved_state.config != different_config
|
||||||
|
assert retrieved_state.system == state.system
|
||||||
|
assert retrieved_state.current_cycle == state.current_cycle
|
||||||
@@ -1,393 +0,0 @@
|
|||||||
from diceplayer import VERSION, logger
|
|
||||||
from diceplayer.player import Player
|
|
||||||
from tests.mocks.mock_inputs import mock_open
|
|
||||||
|
|
||||||
import io
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestPlayer(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
logger.set_logger(stream=io.StringIO())
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
def test_class_instantiation(self):
|
|
||||||
# This file does not exist and it will be mocked
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
|
|
||||||
self.assertIsInstance(player, Player)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
def test_start(self):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
|
|
||||||
player.gaussian_start = mock.MagicMock()
|
|
||||||
player.dice_start = mock.MagicMock()
|
|
||||||
|
|
||||||
player.start()
|
|
||||||
|
|
||||||
self.assertEqual(player.dice_start.call_count, 3)
|
|
||||||
self.assertEqual(player.gaussian_start.call_count, 3)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
@mock.patch("diceplayer.player.Path")
|
|
||||||
def test_create_simulation_dir_if_already_exists(self, mock_path):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
mock_path.return_value.exists.return_value = True
|
|
||||||
|
|
||||||
with self.assertRaises(FileExistsError):
|
|
||||||
player.create_simulation_dir()
|
|
||||||
|
|
||||||
self.assertTrue(mock_path.called)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
@mock.patch("diceplayer.player.Path")
|
|
||||||
def test_create_simulation_dir_if_not_exists(self, mock_path):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
mock_path.return_value.exists.return_value = False
|
|
||||||
|
|
||||||
player.create_simulation_dir()
|
|
||||||
|
|
||||||
self.assertTrue(mock_path.called)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
@mock.patch("diceplayer.player.VERSION", "test")
|
|
||||||
@mock.patch("diceplayer.player.sys")
|
|
||||||
@mock.patch("diceplayer.player.weekday_date_time")
|
|
||||||
def test_print_keywords(self, mock_date_func, mock_sys):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
|
|
||||||
mock_sys.version = "TEST"
|
|
||||||
mock_date_func.return_value = "00 Test 0000 at 00:00:00"
|
|
||||||
|
|
||||||
with self.assertLogs() as cm:
|
|
||||||
player.print_keywords()
|
|
||||||
|
|
||||||
expected_output = [
|
|
||||||
"INFO:diceplayer:##########################################################################################\n############# Welcome to DICEPLAYER version test #############\n##########################################################################################\n",
|
|
||||||
"INFO:diceplayer:Your python version is TEST\n",
|
|
||||||
"INFO:diceplayer:Program started on 00 Test 0000 at 00:00:00\n",
|
|
||||||
"INFO:diceplayer:Environment variables:",
|
|
||||||
"INFO:diceplayer:OMP_STACKSIZE = Not set\n",
|
|
||||||
"INFO:diceplayer:------------------------------------------------------------------------------------------\n DICE variables being used in this run:\n------------------------------------------------------------------------------------------\n",
|
|
||||||
"INFO:diceplayer:dens = 0.75",
|
|
||||||
"INFO:diceplayer:isave = 1000",
|
|
||||||
"INFO:diceplayer:ljname = phb.ljc",
|
|
||||||
"INFO:diceplayer:nmol = [ 1 50 ]",
|
|
||||||
"INFO:diceplayer:nstep = [ 2000 3000 4000 ]",
|
|
||||||
"INFO:diceplayer:outname = phb",
|
|
||||||
"INFO:diceplayer:press = 1.0",
|
|
||||||
"INFO:diceplayer:progname = ~/.local/bin/dice",
|
|
||||||
"INFO:diceplayer:randominit = first",
|
|
||||||
"INFO:diceplayer:temp = 300.0",
|
|
||||||
"INFO:diceplayer:------------------------------------------------------------------------------------------\n GAUSSIAN variables being used in this run:\n------------------------------------------------------------------------------------------\n",
|
|
||||||
"INFO:diceplayer:chg_tol = 0.01",
|
|
||||||
"INFO:diceplayer:keywords = freq",
|
|
||||||
"INFO:diceplayer:level = MP2/aug-cc-pVDZ",
|
|
||||||
"INFO:diceplayer:pop = chelpg",
|
|
||||||
"INFO:diceplayer:qmprog = g16",
|
|
||||||
"INFO:diceplayer:\n",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(cm.output, expected_output)
|
|
||||||
|
|
||||||
def test_validate_atom_dict(self):
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid number of fields for site 1 for molecule type 1.",
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": "",
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception), "Invalid lbl fields for site 1 for molecule type 1."
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": "",
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception), "Invalid na fields for site 1 for molecule type 1."
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": "",
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid rx fields for site 1 for molecule type 1. Value must be a float.",
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": "",
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid ry fields for site 1 for molecule type 1. Value must be a float.",
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": "",
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid rz fields for site 1 for molecule type 1. Value must be a float.",
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": "",
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid chg fields for site 1 for molecule type 1. Value must be a float.",
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": "",
|
|
||||||
"sig": 1.0,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid eps fields for site 1 for molecule type 1. Value must be a float.",
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
Player.validate_atom_dict(
|
|
||||||
molecule_type=0,
|
|
||||||
molecule_site=0,
|
|
||||||
atom_dict={
|
|
||||||
"lbl": 1.0,
|
|
||||||
"na": 1,
|
|
||||||
"rx": 1.0,
|
|
||||||
"ry": 1.0,
|
|
||||||
"rz": 1.0,
|
|
||||||
"chg": 1.0,
|
|
||||||
"eps": 1.0,
|
|
||||||
"sig": "",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Invalid sig fields for site 1 for molecule type 1. Value must be a float.",
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
@mock.patch("diceplayer.player.Path.exists", return_value=True)
|
|
||||||
def test_read_potentials(self, mock_path_exists):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(player.system.molecule[0].molname, "TEST")
|
|
||||||
self.assertEqual(len(player.system.molecule[0].atom), 1)
|
|
||||||
|
|
||||||
self.assertEqual(player.system.molecule[1].molname, "PLACEHOLDER")
|
|
||||||
self.assertEqual(len(player.system.molecule[1].atom), 1)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
@mock.patch("diceplayer.player.Path.exists")
|
|
||||||
def test_read_potentials_error(self, mock_path_exists):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
|
|
||||||
# Testing file not found error
|
|
||||||
mock_path_exists.return_value = False
|
|
||||||
with self.assertRaises(RuntimeError) as context:
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(str(context.exception), "Potential file phb.ljc not found.")
|
|
||||||
|
|
||||||
# Enabling file found for next tests
|
|
||||||
mock_path_exists.return_value = True
|
|
||||||
|
|
||||||
# Testing combrule error
|
|
||||||
with self.assertRaises(SystemExit) as context:
|
|
||||||
player.config.dice.ljname = "phb.error.combrule.ljc"
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Error: expected a '*' or a '+' sign in 1st line of file phb.error.combrule.ljc",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Testing ntypes error
|
|
||||||
with self.assertRaises(SystemExit) as context:
|
|
||||||
player.config.dice.ljname = "phb.error.ntypes.ljc"
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Error: expected an integer in the 2nd line of file phb.error.ntypes.ljc",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Testing ntypes error on config
|
|
||||||
with self.assertRaises(SystemExit) as context:
|
|
||||||
player.config.dice.ljname = "phb.error.ntypes.config.ljc"
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Error: number of molecule types in file phb.error.ntypes.config.ljc "
|
|
||||||
"must match that of 'nmol' keyword in config file",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Testing nsite error
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
player.config.dice.ljname = "phb.error.nsites.ljc"
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Error: expected nsites to be an integer for molecule type 1",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Testing molname error
|
|
||||||
with self.assertRaises(ValueError) as context:
|
|
||||||
player.config.dice.ljname = "phb.error.molname.ljc"
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
str(context.exception),
|
|
||||||
"Error: expected nsites and molname for the molecule type 1",
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
@mock.patch("diceplayer.player.Path.exists", return_value=True)
|
|
||||||
def test_print_potentials(self, mock_path_exists):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
player.read_potentials()
|
|
||||||
|
|
||||||
with self.assertLogs(level="INFO") as context:
|
|
||||||
player.print_potentials()
|
|
||||||
|
|
||||||
expected_output = [
|
|
||||||
"INFO:diceplayer:==========================================================================================\n Potential parameters from file phb.ljc:\n------------------------------------------------------------------------------------------\n",
|
|
||||||
"INFO:diceplayer:Combination rule: *",
|
|
||||||
"INFO:diceplayer:Types of molecules: 2\n",
|
|
||||||
"INFO:diceplayer:1 atoms in molecule type 1:",
|
|
||||||
"INFO:diceplayer:---------------------------------------------------------------------------------",
|
|
||||||
"INFO:diceplayer:Lbl AN X Y Z Charge Epsilon Sigma Mass",
|
|
||||||
"INFO:diceplayer:---------------------------------------------------------------------------------",
|
|
||||||
"INFO:diceplayer:1 1 0.00000 0.00000 0.00000 0.000000 0.00000 0.0000 1.0079",
|
|
||||||
"INFO:diceplayer:\n",
|
|
||||||
"INFO:diceplayer:1 atoms in molecule type 2:",
|
|
||||||
"INFO:diceplayer:---------------------------------------------------------------------------------",
|
|
||||||
"INFO:diceplayer:Lbl AN X Y Z Charge Epsilon Sigma Mass",
|
|
||||||
"INFO:diceplayer:---------------------------------------------------------------------------------",
|
|
||||||
"INFO:diceplayer:1 1 0.00000 0.00000 0.00000 0.000000 0.00000 0.0000 1.0079",
|
|
||||||
"INFO:diceplayer:\n",
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(context.output, expected_output)
|
|
||||||
|
|
||||||
@mock.patch("builtins.open", mock_open)
|
|
||||||
def test_dice_start(self):
|
|
||||||
player = Player("control.test.yml")
|
|
||||||
player.dice_interface = mock.MagicMock()
|
|
||||||
player.dice_interface.start = mock.MagicMock()
|
|
||||||
|
|
||||||
player.dice_start(1)
|
|
||||||
|
|
||||||
player.dice_interface.start.assert_called_once()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
37
tests/utils/test_potential.py
Normal file
37
tests/utils/test_potential.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
from diceplayer.config import PlayerConfig
|
||||||
|
from diceplayer.environment import System
|
||||||
|
from diceplayer.utils.potential import read_system_from_phb
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class TestPotential:
|
||||||
|
@pytest.fixture
|
||||||
|
def player_config(self) -> PlayerConfig:
|
||||||
|
return PlayerConfig.model_validate(
|
||||||
|
{
|
||||||
|
"type": "both",
|
||||||
|
"mem": 12,
|
||||||
|
"max_cyc": 100,
|
||||||
|
"switch_cyc": 50,
|
||||||
|
"ncores": 4,
|
||||||
|
"dice": {
|
||||||
|
"nprocs": 4,
|
||||||
|
"ljname": "phb.ljc.example",
|
||||||
|
"outname": "test",
|
||||||
|
"dens": 1.0,
|
||||||
|
"nmol": [12, 16],
|
||||||
|
"nstep": [1, 1],
|
||||||
|
},
|
||||||
|
"gaussian": {
|
||||||
|
"level": "test",
|
||||||
|
"qmprog": "g16",
|
||||||
|
"keywords": "test",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_read_phb(self, player_config: PlayerConfig):
|
||||||
|
system = read_system_from_phb(player_config)
|
||||||
|
|
||||||
|
assert isinstance(system, System)
|
||||||
Reference in New Issue
Block a user