feat: reads potentions from ljc file
This commit is contained in:
@@ -6,6 +6,7 @@ import pytest
|
||||
class TestDiceConfig:
|
||||
def test_class_instantiation(self):
|
||||
dice_dto = DiceConfig(
|
||||
nprocs=1,
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
@@ -18,6 +19,7 @@ class TestDiceConfig:
|
||||
def test_validate_jname(self):
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
nprocs=1,
|
||||
ljname=None,
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
@@ -30,6 +32,7 @@ class TestDiceConfig:
|
||||
def test_validate_outname(self):
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
nprocs=1,
|
||||
ljname="test",
|
||||
outname=None,
|
||||
dens=1.0,
|
||||
@@ -42,6 +45,7 @@ class TestDiceConfig:
|
||||
def test_validate_dens(self):
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
nprocs=1,
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=None,
|
||||
@@ -54,6 +58,7 @@ class TestDiceConfig:
|
||||
def test_validate_nmol(self):
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
nprocs=1,
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
@@ -66,6 +71,7 @@ class TestDiceConfig:
|
||||
def test_validate_nstep(self):
|
||||
with pytest.raises(ValueError) as ex:
|
||||
DiceConfig(
|
||||
nprocs=1,
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
@@ -78,6 +84,7 @@ class TestDiceConfig:
|
||||
def test_from_dict(self):
|
||||
dice_dto = DiceConfig.model_validate(
|
||||
{
|
||||
"nprocs": 1,
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
|
||||
@@ -11,6 +11,7 @@ class TestPlayerConfig:
|
||||
@pytest.fixture
|
||||
def dice_payload(self) -> dict[str, Any]:
|
||||
return {
|
||||
"nprocs": 4,
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
@@ -35,7 +36,6 @@ class TestPlayerConfig:
|
||||
"mem": 12,
|
||||
"max_cyc": 100,
|
||||
"switch_cyc": 50,
|
||||
"nprocs": 4,
|
||||
"ncores": 4,
|
||||
"dice": dice_payload,
|
||||
"gaussian": gaussian_payload,
|
||||
@@ -57,7 +57,6 @@ class TestPlayerConfig:
|
||||
mem=12,
|
||||
max_cyc=100,
|
||||
switch_cyc=50,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
dice=dice_config,
|
||||
gaussian=gaussian_config,
|
||||
@@ -75,7 +74,6 @@ class TestPlayerConfig:
|
||||
mem=12,
|
||||
max_cyc=100,
|
||||
switch_cyc=50,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
altsteps=0,
|
||||
dice=dice_config,
|
||||
|
||||
@@ -20,9 +20,9 @@ class TestDiceInput:
|
||||
"mem": 12,
|
||||
"max_cyc": 100,
|
||||
"switch_cyc": 50,
|
||||
"nprocs": 4,
|
||||
"ncores": 4,
|
||||
"dice": {
|
||||
"nprocs": 4,
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
|
||||
@@ -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,32 +0,0 @@
|
||||
from typing_extensions import List
|
||||
|
||||
import itertools
|
||||
|
||||
|
||||
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
|
||||
@@ -16,9 +16,9 @@ class TestStateHandler:
|
||||
mem=12,
|
||||
max_cyc=100,
|
||||
switch_cyc=50,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
dice=DiceConfig(
|
||||
nprocs=4,
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
|
||||
38
tests/utils/test_potential.py
Normal file
38
tests/utils/test_potential.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from diceplayer.config import PlayerConfig
|
||||
from diceplayer.environment import System
|
||||
from diceplayer.utils.potential import read_system_from_phb
|
||||
|
||||
|
||||
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