Skip to content

Commit

Permalink
Set up options to select driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Nov 11, 2024
1 parent f5e2034 commit bd7ff8b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions drivers/py/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Minimal example of a Python driver connecting to i-PI and exchanging energy, forces, etc.
"""


def recv_data(sock, data):
"""Fetches binary data from i-PI socket."""
blen = data.itemsize * data.size
Expand Down
38 changes: 37 additions & 1 deletion ipi/engine/forcefields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ipi.utils.io import read_file
from ipi.utils.units import unit_to_internal
from ipi.utils.distance import vector_separation
from ipi.pes import __drivers__

try:
import plumed
Expand Down Expand Up @@ -392,7 +393,42 @@ def evaluate(self, request):


class FFDirect(FFEval):
pass
def __init__(
self,
latency=1.0,
offset=0.0,
name="",
pars=None,
dopbc=False,
active=np.array([-1]),
threaded=False,
pes="dummy",
):
"""Initialises FFDirect.
Args:
latency: The number of seconds the socket will wait before updating
the client list.
offset: A constant offset subtracted from the energy value given by the
client.
name: The name of the forcefield.
pars: A dictionary used to initialize the forcefield, if required.
Of the form {'name1': value1, 'name2': value2, ... }.
dopbc: Decides whether or not to apply the periodic boundary conditions
before sending the positions to the client code.
active: Indexes of active atoms in this forcefield
"""

super().__init__(latency, offset, name, pars, dopbc, active, threaded)

self.pes = pes
# TODO sanitize the handling of pars
self.driver = __drivers__[self.pes]("", verbosity.high)

def evaluate(self, request):
request["result"] = list(self.driver(request["cell"][0], request["pos"]))
request["status"] = "Done"


class FFLennardJones(FFEval):
Expand Down
33 changes: 31 additions & 2 deletions ipi/inputs/forcefields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
FFCavPhSocket,
)
from ipi.interfaces.sockets import InterfaceSocket
from ipi.pes import __drivers__
import ipi.engine.initializer
from ipi.inputs.initializer import *
from ipi.utils.inputvalue import *
Expand Down Expand Up @@ -341,14 +342,42 @@ def check(self):


class InputFFDirect(InputForceField):
fields = {
"pes": (
InputValue,
{
"dtype": str,
"default": "dummy",
"options": list(__drivers__.keys()),
"help": "Type of PES that should be used to evaluate the forcefield",
},
),
}
fields.update(InputForceField.fields)

attribs = {}
attribs.update(InputForceField.attribs)

default_help = """ Direct potential that evaluates forces through a Python
call, using PES providers from a list of possible external codes. """
default_label = "FFDirect"

_FFCLASS = FFDirect
def store(self, ff):
super().store(ff)
self.pes.store(ff.pes)

def fetch(self):
super().fetch()

return FFDirect(
pars=self.parameters.fetch(),
name=self.name.fetch(),
latency=self.latency.fetch(),
offset=self.offset.fetch(),
dopbc=self.pbc.fetch(),
threaded=self.threaded.fetch(),
pes=self.pes.fetch(),
)


class InputFFLennardJones(InputForceField):
Expand Down Expand Up @@ -438,7 +467,7 @@ class InputFFDebye(InputForceField):
"default": input_default(factory=np.zeros, args=(0,)),
"help": "Specifies the Hessian of the harmonic potential. "
"Default units are atomic. Units can be specified only by xml attribute. "
"Implemented options are: 'atomic_unit', 'ev/ang\^2'",
r"Implemented options are: 'atomic_unit', 'ev/ang^2'",
"dimension": "hessian",
},
),
Expand Down
3 changes: 2 additions & 1 deletion ipi_tests/profiling/classical_md_direct/input.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<simulation verbosity='medium' threading='false' safe_stride='100'>
<ffdirect name='driver'>
<ffdirect name='driver'>
<pes> dummy </pes>
<latency> 1.00000000e-04</latency>
</ffdirect>
<total_steps>10000</total_steps>
Expand Down

0 comments on commit bd7ff8b

Please sign in to comment.