Пример #1
0
def test_nodes():
    port_num = 9001
    mdi_driver_options = "-role DRIVER -name driver -method TCP -port " + str(
        port_num)

    # Get the number of nodes
    #driver_proc = subprocess.Popen([sys.executable, "min_driver.py", "-command", "<NNODES",
    #                                "-nreceive", "1", "-rtype", "MDI_INT",
    #                                "-mdi", mdi_driver_options],
    #                               stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd="./drivers")

    # Run LAMMPS as an engine
    mdi_engine_options = "-role ENGINE -name TESTCODE -method TCP -hostname localhost -port " + str(
        port_num)
    working_dir = "../../user/mdi_tests/test1"
    user_path = os.environ['USER_PATH']
    os.system("rm -rf ./_work")
    os.system("cp -r " + str(working_dir) + " _work")
    engine_path = str(user_path) + "/lammps/src/lmp_mdi"
    engine_proc = subprocess.Popen(
        [engine_path, "-mdi", mdi_engine_options, "-in", "lammps.in"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd="./_work")

    # Convert the driver's output into a string
    #driver_tup = driver_proc.communicate()
    #driver_out = format_return(driver_tup[0])
    #driver_err = format_return(driver_tup[1])

    #print("CHECK_MDI_NODES.PY")
    #print("   Driver out: " + str(driver_out))
    #print("   Driver err: " + str(driver_err))

    mdi.MDI_Init(mdi_driver_options, None)
    comm = mdi.MDI_Accept_Communicator()
    nnodes = mdi.MDI_Get_NNodes(comm)
    print("NNodes: " + str(nnodes))
    nodes = [mdi.MDI_Get_Node(inode, comm) for inode in range(nnodes)]
    print("Nodes: " + str(nodes))
    for node in nodes:
        ncommands = mdi.MDI_Get_NCommands(node, comm)
        commands = [
            mdi.MDI_Get_Command(node, icommand, comm)
            for icommand in range(ncommands)
        ]
        print("Commands: " + str(commands))
    mdi.MDI_Send_Command("EXIT", comm)

    engine_tup = engine_proc.communicate()
    engine_out = format_return(engine_tup[0])
    engine_err = format_return(engine_tup[1])
Пример #2
0
import sys
import mdi

use_mpi4py = False
try:
    from mpi4py import MPI
    use_mpi4py = True
except:
    pass

# Initialize the MDI Library
mdi.MDI_Init(sys.argv[2])

# Connect to the engine
comm = mdi.MDI_Accept_communicator()

# Determine the name of the engine
mdi.MDI_Send_Command("<NAME", comm)
name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)

print("Engine name: " + str(name))

# Send the "EXIT" command to the engine
mdi.MDI_Send_Command("EXIT", comm)
Пример #3
0
sys.path.insert(0, '../lib/mdi_build/molssi_driver_interface')

import mdi as mdi

niterations = 10

# initialize the socket
mdi.MDI_Init(sys.argv[2], None)

# connect to the production codes
ncodes = 2
for icode in range(ncodes):
    comm = mdi.MDI_Accept_Communicator()

    # get the name of the code
    mdi.MDI_Send_Command("<NAME", comm)
    name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)
    print('Received connection: ' + str(name))

    if name.strip() == 'QM':
        qm_comm = comm
    elif name.strip() == 'MM':
        mm_comm = comm
    else:
        raise ValueError('Production code name not recognized')

# receive the number of atoms from the MM code
mdi.MDI_Send_Command("<NATOMS", mm_comm)
natom = mdi.MDI_Recv(1, mdi.MDI_INT, mm_comm)

# have the MD code initialize a new MD simulation
Пример #4
0
sys.path.insert(0, '../lib/mdi_build/molssi_driver_interface')

import mdi as mdi

niterations = 10

# initialize the socket
mdi.MDI_Init(sys.argv[2],None)

# connect to the production codes
ncodes = 1
for icode in range(ncodes):
    comm = mdi.MDI_Accept_Communicator()

    # get the name of the code
    mdi.MDI_Send_Command("<NAME", comm)
    name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)
    print('Received connection: ' + str(name))

    if name.strip() == 'MM':
        mm_comm = comm
    else:
        raise ValueError('Production code name not recognized')



# have the MD code initialize a new MD simulation
mdi.MDI_Send_Command("MD_INIT", mm_comm)

for iiter in range(niterations):
Пример #5
0
    if arg == "-mdi":
        # Initialize MDI
        if len(sys.argv) <= iarg + 1:
            raise Exception("Argument to -mdi option not found")
        mdi.MDI_Init(sys.argv[iarg + 1], None)
        iarg += 1
    else:
        raise Exception("Unrecognized argument")

    iarg += 1

# Connect to the engine
comm = mdi.MDI_Accept_Communicator()

# Get the name of the engine, which will be checked and verified at the end
mdi.MDI_Send_Command("<NAME", comm)
initial_name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)

##############
print("AAA")
#mdi.MDI_Send_Command("@INIT_OPTG", comm)
print("BBB")

# Verify that the engine is still responsive
mdi.MDI_Send_Command("<NAME", comm)
final_name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)
assert initial_name == final_name

mdi.MDI_Send_Command("@INIT_MD", comm)
for i in range(100):
    mdi.MDI_Send_Command("@", comm)
Пример #6
0
# Set world_comm to the correct intra-code MPI communicator
world_comm = mdi.MDI_MPI_get_world_comm()

# Get the MPI rank of this process
if world_comm is not None:
    my_rank = world_comm.Get_rank()
else:
    my_rank = 0

# Accept a connection from an external driver
mdi_comm = mdi.MDI_Accept_Communicator()

# This is the part where you can use MDI
if my_rank == 0:
    # <NAME
    mdi.MDI_Send_Command("<NAME", mdi_comm)
    engine_name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, mdi_comm)
    print("ENGINE NAME: " + str(engine_name))

    # <ENERGY
    mdi.MDI_Send_Command("<ENERGY", mdi_comm)
    energy = mdi.MDI_Recv(1, mdi.MDI_DOUBLE, mdi_comm)
    print("ENERGY:  " + str(energy))

    # <KE
    mdi.MDI_Send_Command("<KE", mdi_comm)
    energy = mdi.MDI_Recv(1, mdi.MDI_DOUBLE, mdi_comm)
    print("KE:       " + str(energy))

    # <KE_ELEC
    mdi.MDI_Send_Command("<KE_ELEC", mdi_comm)
Пример #7
0
    def callback(self, mpi_comm, mdi_comm):

        my_rank = mpi_comm.Get_rank()

        print("PRE MDI SEND <NAME")
        mdi.MDI_Send_Command("<NAME", mdi_comm)
        print("POST MDI SEND <NAME")
        name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, mdi_comm)
        if my_rank == 0:
            print("Engine name: " + str(name))

        # Send the cell dimensions to the plugin
        mdi.MDI_Send_Command(">CELL", mdi_comm)
        mdi.MDI_Send(self.cell, 9, mdi.MDI_DOUBLE, mdi_comm)

        # Find out if the plugin supports the >NATOMS command
        natoms_supported = 0
        natoms_supported = mdi.MDI_Check_command_exists("@DEFAULT", ">NATOMS", mdi_comm)
        natoms_supported = mpi_comm.bcast(natoms_supported, root=0)

        if natoms_supported:

            # Send the number of atoms to the plugin
            mdi.MDI_Send_Command(">NATOMS", mdi_comm)
            mdi.MDI_Send(self.natoms, 1, mdi.MDI_INT, mdi_comm)

        else:

            # We will assume the plugin has read the correct number
            #    of atoms from an input file.
            pass

        # Find out if the plugin supports the >ELEMENTS command
        elem_supported = 0
        elem_supported = mdi.MDI_Check_command_exists("@DEFAULT", ">ELEMENTS", mdi_comm)
        elem_supported = mpi_comm.bcast(elem_supported, root=0)

        if elem_supported:

            # Send the number of elements to the plugin
            mdi.MDI_Send_Command(">ELEMENTS", mdi_comm)
            mdi.MDI_Send(self.elements, self.natoms, mdi.MDI_INT, mdi_comm)

        else:

            # We will assume the plugin has read the correct element
            #    of each atom from an input file.
            pass

        # Send the nuclear coordinates to the plugin
        mdi.MDI_Send_Command(">COORDS", mdi_comm)
        mdi.MDI_Send(self.coords, 3*self.natoms, mdi.MDI_DOUBLE, mdi_comm)

        # Receive the energy of the system from the plugin
        mdi.MDI_Send_Command("<ENERGY", mdi_comm)
        energy = mdi.MDI_Recv(1, mdi.MDI_DOUBLE, mdi_comm)
        if my_rank == 0:
            print("ENERGY: " + str(energy))
        
        # Receive the nuclear forces from the plugin
        mdi.MDI_Send_Command("<FORCES", mdi_comm)
        forces = mdi.MDI_Recv(3*self.natoms, mdi.MDI_DOUBLE, mdi_comm)
        if my_rank == 0:
            print("FORCES: " + str(forces))

        # Send the "EXIT" command to the plugin
        mdi.MDI_Send_Command("EXIT", mdi_comm)

        return 0
Пример #8
0
niterations = 10
for iiteration in range(niterations):

    # Create and connect to a library instance that spans the MPI task communicator
    MDIEngine("-role ENGINE -name MM -method LIBRARY -driver_name driver",
              mpi_task_comm)
    comm = mdi.MDI_Accept_Communicator()

    # Create and connect to a library instance that spans MPI_COMM_WORLD
    MDIEngine("-role ENGINE -name unsplit -method LIBRARY -driver_name driver",
              mpi_world)
    comm_unsplit = mdi.MDI_Accept_Communicator()

    # Communicate with the library instance that spans the MPI task communicator
    mdi.MDI_Send_Command("<NATOMS", comm)
    natoms = mdi.MDI_Recv(1, mdi.MDI_INT, comm)
    if world_rank == 0:
        print("NATOMS: " + str(natoms))
    mdi.MDI_Send_Command("EXIT", comm)

    # Communicate with the library instance that spans MPI_COMM_WORLD
    mdi.MDI_Send_Command("<NATOMS", comm_unsplit)
    natoms = mdi.MDI_Recv(1, mdi.MDI_INT, comm_unsplit)
    if world_rank == 0:
        print("NATOMS: " + str(natoms))
    mdi.MDI_Send_Command("EXIT", comm_unsplit)

if use_mpi4py:
    mpi_world.Barrier()
Пример #9
0
sys.path.insert(0, '../lib/mdi_build/molssi_driver_interface')

import mdi as mdi

niterations = 1000

# initialize the socket
mdi.MDI_Init(sys.argv[2], None)

# connect to the production codes
ncodes = 1
for icode in range(ncodes):
    comm = mdi.MDI_Accept_Communicator()

    # get the name of the code
    mdi.MDI_Send_Command("<NAME", comm)
    name = mdi.MDI_Recv(mdi.MDI_NAME_LENGTH, mdi.MDI_CHAR, comm)
    print('Received connection: ' + str(name))

    if name.strip() == 'MM':
        mm_comm = comm
    else:
        raise ValueError('Production code name not recognized')

# receive the number of atoms
mdi.MDI_Send_Command("<NATOMS", mm_comm)
natoms = mdi.MDI_Recv(1, mdi.MDI_INT, mm_comm)

# receive the number of atom types
mdi.MDI_Send_Command("<NTYPES", mm_comm)
ntypes = mdi.MDI_Recv(1, mdi.MDI_INT, mm_comm)
Пример #10
0
import mdi
import sys

mdi.MDI_Init(sys.argv[2], None)

# Connect to the engine
comm = mdi.MDI_Accept_Communicator()

mdi.MDI_Send_Command("UNSUPPORTED", comm)

print(" Engine name: " + str(name))

mdi.MDI_Send_Command("EXIT", comm)