Skip to content

Commit

Permalink
Merge pull request #4 from taylor-a-barnes/launch
Browse files Browse the repository at this point in the history
Fix MDI launch script
  • Loading branch information
godotalgorithm authored Oct 23, 2024
2 parents 58abdcf + bb91e8c commit 65b75cf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
9 changes: 3 additions & 6 deletions mdimechanic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ run_scripts:
script:
- cd tests/formic
- cp formic_acid.mop formic_acid2.mop
- python launcher.py > launcher.out &
- python driver.py -mdi "-role DRIVER -name driver -method LINK" > driver2.out &
- wait
- cat launcher.out
- cat driver2.out
- LD_PRELOAD=/repo/build/mopac/build/mdi_build-prefix/src/mdi_build-build/MDI_Library/libmdi.so python launcher.py
- cat formic_acid2.out
- rm formic_acid2.mop

Expand All @@ -66,7 +62,8 @@ run_scripts:
script:
- cd tests/formic
- cp formic_acid.mop formic_acid3.mop
- python opener.py -mdi "-role DRIVER -name driver -method LINK -plugin_path /repo/build/mopac/build" > opener.out
#- python opener.py -mdi "-role DRIVER -name driver -method LINK -plugin_path /repo/build/mopac/build" > opener.out
- LD_PRELOAD=/repo/build/mopac/build/mdi_build-prefix/src/mdi_build-build/MDI_Library/libmdi.so python opener.py -mdi "-role DRIVER -name driver -method LINK -plugin_path /repo/build/mopac/build"
- cat opener.out
- cat formic_acid3.out
- rm formic_acid3.mop
60 changes: 56 additions & 4 deletions tests/formic/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,60 @@
import mdi
import sys

# Initiate MDI
mdi.MDI_Init("-mdi")

# Open plugin
mdi.MDI_Launch_plugin("mopac", "formic_acid3 -mdi \"-role ENGINE -name mopac -method LINK -plugin_path /repo/build/mopac/build\"", None, None, None)
def driver_callback(mpi_comm, comm, class_object):

# Get the name of the engine, which will be checked and verified at the end
mdi.MDI_Send_Command("<NAME", comm)
engine_name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)
print(f"Engine name: {engine_name}")

# Get the node name
mdi.MDI_Send_Command("<@", comm)
node_name = mdi.MDI_Recv(mdi.MDI_COMMAND_LENGTH, mdi.MDI_CHAR, comm)
print(f"Node name: {node_name}")

# Get data from the first geometry of the molecule
mdi.MDI_Send_Command("<NATOMS", comm)
natoms = mdi.MDI_Recv(1, mdi.MDI_INT, comm)
print(f"NATOMS: {natoms}")

mdi.MDI_Send_Command("<COORDS", comm)
coords = mdi.MDI_Recv(3 * natoms, mdi.MDI_DOUBLE, comm)
print(f"COORDS: {coords}")

mdi.MDI_Send_Command("<ENERGY", comm)
energy = mdi.MDI_Recv(1, mdi.MDI_DOUBLE, comm)
print(f"ENERGY: {energy}")

# Adjust the geometry of the molecule
print("Sending new coordinates...")
coords2 = [coord*1.1 for coord in coords]
mdi.MDI_Send_Command(">COORDS", comm)
mdi.MDI_Send(coords2, 3 * natoms, mdi.MDI_DOUBLE, comm)

# Get data from the second geometry of the molecule
mdi.MDI_Send_Command("<NATOMS", comm)
natoms = mdi.MDI_Recv(1, mdi.MDI_INT, comm)
print(f"NATOMS: {natoms}")

mdi.MDI_Send_Command("<COORDS", comm)
coords = mdi.MDI_Recv(3 * natoms, mdi.MDI_DOUBLE, comm)
print(f"COORDS: {coords}")

mdi.MDI_Send_Command("<ENERGY", comm)
energy = mdi.MDI_Recv(1, mdi.MDI_DOUBLE, comm)
print(f"ENERGY: {energy}")

# Normal exit
mdi.MDI_Send_Command("EXIT", comm)

return 0


if __name__ == "__main__":
# Initiate MDI
mdi.MDI_Init("-role DRIVER -name driver -method LINK -plugin_path /repo/build/mopac/build")

# Launch plugin
mdi.MDI_Launch_plugin("mopac", "formic_acid2 -mdi \"-role ENGINE -name mopac -method LINK -plugin_path /repo/build/mopac/build\"", None, driver_callback, None)

0 comments on commit 65b75cf

Please sign in to comment.