Skip to content

Commit

Permalink
Update I-PI driver (#58)
Browse files Browse the repository at this point in the history
* update IPI driver

* add note on I-PI driver use

* autodoc update

* fix typos
  • Loading branch information
tjjarvinen authored Nov 5, 2023
1 parent 32b8727 commit 251414a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ACEmd"
uuid = "69e0c927-b120-467d-b2b3-5b6842148cf4"
authors = ["Teemu Järvinen <[email protected]> and contributors"]
version = "0.1.7"
version = "0.1.8-DEV"

[deps]
ACE1 = "e3f9bc04-086e-409a-ba78-e9769fe067bb"
Expand Down
6 changes: 3 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CurrentModule = ACEmd

[ACEmd](https://github.com/acesuit/ACEmd.jl) is molecular dynamics interface for Julia ACE. All MD use cases should use this package.

ACEmd is fully [AtomsBase](https://github.com/JuliaMolSim/AtomsBase.jl) compatable and you should use AtomsBase over older JuLIP. You can still use JuLIP `Atoms` type as an input, while in a long run JuLIP will be decomissioned.
ACEmd is fully [AtomsBase](https://github.com/JuliaMolSim/AtomsBase.jl) compatible and you should use AtomsBase over older JuLIP. You can still use JuLIP `Atoms` type as an input, while in a long run JuLIP will be decommissioned.

## Example use case

Expand Down Expand Up @@ -50,7 +50,7 @@ pot_ev = load_ace_model(fname_ace;
ace_energy(pot_ev, data)
```

Alternatively you can overload the default unit by giving it explicitely
Alternatively you can overload the default unit by giving it explicitly

```@repl 1
ace_energy(pot_ev, data; energy_unit=u"hartree")
Expand Down Expand Up @@ -78,5 +78,5 @@ ace_atom_energies(pot, data)
```

```@autodocs
Modules = [ACEmd]
Modules = [ACEmd, ACEmd.IPIprotocol]
```
24 changes: 19 additions & 5 deletions src/submodules/IPIprotocol.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module IPIprotocol
# This is AtomsCalculators implementation for i-PI protocol.
# For reference see https://github.com/i-pi/i-pi/blob/master/drivers/py/driver.py

using ..ACEmd
using AtomsBase
using AtomsCalculators
using Sockets
using StaticArrays
# i-PI example https://github.com/i-pi/i-pi/blob/master/drivers/py/driver.py
using Unitful
using UnitfulAtomic

export run_driver

Expand Down Expand Up @@ -78,8 +82,18 @@ function sendforce(comm, e::Number, forces::AbstractVector, virial::AbstractMatr
write(comm, zero(UInt8) )
end

"""
run_driver(address, potential, init_structure; port=31415, unixsocket=false )
function run_driver(address, pot::ACEmd.ACEpotential, init_structure; port=31415, unixsocket=false )
Connect I-PI driver to server at given `address`. Use kword `port` (default 31415) to
specify port. If kword `unixsocket` is true, `address` is understood to be the name of the socket
and `port` option is ignored.
You need to give initial structure as I-PI protocol does not transfer atom symbols.
This means that, if you want to change the number of atoms or their symbols, you need
to lauch a new driver.
"""
function run_driver(address, potential, init_structure; port=31415, unixsocket=false )
if unixsocket
comm = connect("/tmp/ipi_"*address)
else
Expand Down Expand Up @@ -119,10 +133,10 @@ function run_driver(address, pot::ACEmd.ACEpotential, init_structure; port=31415
cell = pos[:cell]
@assert length(symbols) == length(positions) "received amount of position data does no match the atomic symbol data"
system = FastSystem(cell, pbc, positions, symbols, anumbers, masses)
data = ace_energy_forces_virial(pot, system)
data = AtomsCalculators.energy_forces_virial(system, potential)
has_data = true
elseif header == "GETFORCE"
sendforce(comm, data["energy"], data["forces"], data["virial"])
sendforce(comm, data[:energy], data[:forces], data[:virial])
has_data = false
elseif header == "EXIT"
@info "Exiting calculator"
Expand Down

0 comments on commit 251414a

Please sign in to comment.