Example #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])
Example #2
0
    def __init__(self, mdi_options, mpi_comm):
        # Initialize the MDI Library
        mdi.MDI_Init(mdi_options, mpi_comm)
        self.mpi_world = mpi_comm
        self.world_rank = 0
        self.world_size = 1
        if use_mpi4py:
            self.mpi_world = mdi.MDI_Get_Intra_Code_MPI_Comm()
            self.world_rank = self.mpi_world.Get_rank()
            self.world_size = self.mpi_world.Get_size()

        # Set the generic execute_command function
        mdi.MDI_Set_Execute_Command_Func(execute_command_general, self)

        self.exit_flag = False

        # Set some dummy molecular properties
        self.natoms = 10 * self.world_size
        self.atoms = [iatom * 1.1 for iatom in range(self.natoms)]
Example #3
0
    elif args[iarg] == "-tol":
        if iarg + 2 > narg: error()
        tol = float(args[iarg + 1])
        if tol < 0.0: error()
        iarg += 2
    elif args[iarg] == "-seed":
        if iarg + 2 > narg: error()
        seed = int(args[iarg + 1])
        if seed <= 0: error()
        iarg += 2
    else:
        error()

if not mdiarg: error()

mdi.MDI_Init(mdiarg)

# LAMMPS engine is a stand-alone code
# world = MPI communicator for just this driver
# invoke perform_tasks() directly

if not plugin:
    world = mdi.MDI_MPI_get_world_comm()
    mdicomm = mdi.MDI_Accept_Communicator()
    perform_tasks(world, mdicomm, None)

# LAMMPS engine is a plugin library
# launch plugin
# MDI will call back to perform_tasks()

if plugin:
Example #4
0
        exit_flag = True
    elif command == "<NATOMS":
        print("SUCCESS")
    else:
        raise Exception("Error in engine_py.py: MDI command not recognized")

    return 0

# get the MPI communicator
if use_mpi4py:
    mpi_world = MPI.COMM_WORLD
else:
    mpi_world = None

# Initialize the MDI Library
mdi.MDI_Init(sys.argv[2],mpi_world)
if use_mpi4py:
    mpi_world = mdi.MDI_Get_Intra_Code_MPI_Comm()
    world_rank = mpi_world.Get_rank()
else:
    world_rank = 0

# Register the supported commands
mdi.MDI_Register_Node("@GLOBAL")
mdi.MDI_Register_Command("@GLOBAL","EXIT")
mdi.MDI_Register_Command("@GLOBAL","<NATOMS")

# Set the generic execute_command function
mdi.MDI_Set_Execute_Command_Func(execute_command, None)

# Connect to the driver
Example #5
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)
Example #6
0
import sys

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)
Example #7
0
command = None
nreceive = None
rtype = None
nsend = None
stype = None

iarg = 1
while iarg < len(sys.argv):
    arg = sys.argv[iarg]

    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
    elif arg == "-command":
        # Set the command
        if len(sys.argv) <= iarg+1:
            raise Exception("Argument to -command option not found")
        command_input = sys.argv[iarg+1]
        iarg += 1
    elif arg == "-nreceive":
        # Set the number of elements to receive
        if len(sys.argv) <= iarg+1:
            raise Exception("Argument to -nreceive option not found")
        nreceive = sys.argv[iarg+1]
        iarg += 1
    elif arg == "-nsend":
        # Set the number of elements to send
Example #8
0
except ImportError:
    use_mpi4py = False

# MPI intra-communicator for all processes running this code
# It should be set to MPI.COMM_WORLD prior to the call to MDI_Init(), as shown below
# Afterwards, you should ALWAYS use this variable instead of MPI.COMM_WORLD
if use_mpi4py:
    world_comm = MPI.COMM_WORLD
else:
    world_comm = None

# Get the command-line options for MDI

# Iniitalize MDI
mdi_options = "-role DRIVER -name driver -method TCP -port 8021"
mdi.MDI_Init(mdi_options)

# 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:
Example #9
0
        help="Command line arguments for the plugin to use.",
        type=str,
        default="",
    )
    
    return parser



# Parse the command-line arguments
parser = create_parser()
args = parser.parse_args()


# Initialize the MDI Library
mdi.MDI_Init( args.mdi )


# We'll try a simple calculation on a water molecule
cell = [
    12.0, 0.0, 0.0,
    0.0, 12.0, 0.0,
    0.0, 0.0, 12.0 ]
elements = [ 8, 1, 1 ]    
coords = [
    0.0, -0.553586, 0.0,
    1.429937, 0.553586, 0.0,
    -1.429937, 0.553586, 0.0
    ]

Example #10
0
command = None
nreceive = None
rtype = None
nsend = None
stype = None

iarg = 1
while iarg < len(sys.argv):
    arg = sys.argv[iarg]

    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])
        iarg += 1
    elif arg == "-command":
        # Set the command
        if len(sys.argv) <= iarg + 1:
            raise Exception("Argument to -command option not found")
        command_input = sys.argv[iarg + 1]
        iarg += 1
    elif arg == "-nreceive":
        # Set the number of elements to receive
        if len(sys.argv) <= iarg + 1:
            raise Exception("Argument to -nreceive option not found")
        nreceive = sys.argv[iarg + 1]
        iarg += 1
    elif arg == "-nsend":
        # Set the number of elements to send