Ejemplo n.º 1
0
def help(name):
    """Print the help message for the named node.

       Parameters
       ----------

       name : str
           The name of the node.
    """

    if type(name) is not str:
        raise TypeError("'name' must be of type 'str'.")

    # Apped the node directory name.
    full_name = _node_dir + "/" + name

    # Make sure the node exists.
    if not _os.path.isfile(full_name):
        if not _os.path.isfile(full_name + ".py"):
            raise ValueError("Cannot find node: '%s'. " % name +
                             "Run 'Node.list()' to see available nodes!")
        else:
            full_name += ".py"

    # Create the command.
    command = "%s/python %s --help" % (_SireBase.getBinDir(), full_name)

    # Run the node as a subprocess.
    proc = _subprocess.run(command, shell=True)
Ejemplo n.º 2
0
    def __init__(self,
                 system,
                 protocol,
                 exe=None,
                 name="somd",
                 platform="CPU",
                 work_dir=None,
                 seed=None,
                 property_map={}):
        """Constructor.

           Parameters
           ----------

           system : :class:`System <BioSimSpace._SireWrappers.System>`
               The molecular system.

           protocol : :class:`Protocol <BioSimSpace.Protocol>`
               The protocol for the SOMD process.

           exe : str
               The full path to the SOMD executable.

           name : str
               The name of the process.

           platform : str
               The platform for the simulation: "CPU", "CUDA", or "OPENCL".

           work_dir :
               The working directory for the process.

           seed : int
               A random number seed.

           property_map : dict
               A dictionary that maps system "properties" to their user defined
               values. This allows the user to refer to properties with their
               own naming scheme, e.g. { "charge" : "my-charge" }
        """

        # Call the base class constructor.
        super().__init__(system, protocol, name, work_dir, seed, property_map)

        # Set the package name.
        self._package_name = "SOMD"

        # This process can generate trajectory data.
        self._has_trajectory = True

        if type(platform) is not str:
            raise TypeError("'platform' must be of type 'str'.")
        else:
            # Strip all whitespace and convert to upper case.
            platform = platform.replace(" ", "").upper()

            # Check for platform support.
            if platform not in self._platforms:
                raise ValueError("Supported platforms are: %s" %
                                 self._platforms.keys())
            else:
                self._platform = self._platforms[platform]

        # If the path to the executable wasn't specified, then use the bundled SOMD
        # executable.
        if exe is None:
            # Generate the name of the SOMD exe.
            if _sys.platform != "win32":
                somd_path = _SireBase.getBinDir()
                somd_suffix = ""
            else:
                somd_path = _os.path.join(
                    _os.path.normpath(_SireBase.getShareDir()), "scripts")
                somd_interpreter = _os.path.join(
                    _os.path.normpath(_SireBase.getBinDir()),
                    "sire_python.exe")
                somd_suffix = ".py"
            if type(self._protocol) is _Protocol.FreeEnergy:
                somd_exe = "somd-freenrg"
            else:
                somd_exe = "somd"
            somd_exe = _os.path.join(somd_path, somd_exe) + somd_suffix
            if not _os.path.isfile(somd_exe):
                raise _MissingSoftwareError(
                    "'Cannot find SOMD executable in expected location: '%s'" %
                    somd_exe)
            if _sys.platform != "win32":
                self._exe = somd_exe
            else:
                self._exe = somd_interpreter
                self._script = somd_exe
        else:
            # Make sure executable exists.
            if _os.path.isfile(exe):
                self._exe = exe
            else:
                raise IOError("SOMD executable doesn't exist: '%s'" % exe)

        # The names of the input files.
        self._rst_file = "%s/%s.rst7" % (self._work_dir, name)
        self._top_file = "%s/%s.prm7" % (self._work_dir, name)

        # The name of the trajectory file.
        self._traj_file = "%s/traj000000001.dcd" % self._work_dir

        # The name of the binary restart file.
        self._restart_file = "%s/latest.rst" % self._work_dir

        # Set the path for the SOMD configuration file.
        self._config_file = "%s/%s.cfg" % (self._work_dir, name)

        # Set the path for the perturbation file.
        self._pert_file = "%s/%s.pert" % (self._work_dir, name)

        # Set the path for the gradient file and create the gradient list.
        self._gradient_file = "%s/gradients.dat" % self._work_dir
        self._gradients = []

        # Create the list of input files.
        self._input_files = [self._config_file, self._rst_file, self._top_file]

        # Initalise the number of moves per cycle.
        self._num_moves = 10000

        # Initialise the buffering frequency.
        self._buffer_freq = 0

        # Now set up the working directory for the process.
        self._setup()
Ejemplo n.º 3
0
                                .absoluteFilePath()
        except:
            pass

if _gmx_exe is None:
    # The user has not told us where it is, so need to look in $PATH.
    try:
        _gmx_exe = _SireBase.findExe("gmx").absoluteFilePath()
    except:
        try:
            _gmx_exe = _SireBase.findExe("gmx_mpi").absoluteFilePath()
        except:
            pass

# Set the bundled GROMACS topology file directory.
_gromacs_path = _path.dirname(_SireBase.getBinDir()) + "/share/gromacs/top"
del _environ
del _SireBase

if not _path.isdir(_gromacs_path):
    _gromacs_path = None

    # Try using the GROMACS exe to get the location of the data directory.
    if _gmx_exe is not None:

        import subprocess as _subprocess

        # Generate the shell command.
        _command = "%s -h 2>&1 | grep 'Data prefix' | awk -F ':' '{print $2}'" % _gmx_exe

        # Run the command.
Ejemplo n.º 4
0
def run(name, args={}):
    """Run a node.

       Parameters
       ----------

       name : str
           The name of the node.

       args : dict
           A dictionary of arguments to be passed to the node.

       Returns
       -------

       output : dict
           A dictionary containing the output of the node.
    """

    # Validate the input.

    if type(name) is not str:
        raise TypeError("'name' must be of type 'str'.")

    if type(args) is not dict:
        raise TypeError("'args' must be of type 'dict'.")

    # Apped the node directory name.
    full_name = _node_dir + "/" + name

    # Make sure the node exists.
    if not _os.path.isfile(full_name):
        if not _os.path.isfile(full_name + ".py"):
            raise ValueError("Cannot find node: '%s'. " % name +
                             "Run 'Node.list()' to see available nodes!")
        else:
            full_name += ".py"

    # Write a YAML configuration file for the BioSimSpace node.
    if len(args) > 0:
        with open("input.yaml", "w") as file:
            _yaml.dump(args, file, default_flow_style=False)

        # Create the command.
        command = "%s/python %s --config input.yaml" % (_SireBase.getBinDir(),
                                                        full_name)

    # No arguments.
    else:
        command = "%s/python %s" % (_SireBase.getBinDir(), full_name)

    # Run the node as a subprocess.
    proc = _subprocess.run(command, shell=True)

    if proc.returncode == 0:
        # Read the output YAML file into a dictionary.
        with open("output.yaml", "r") as file:
            output = _yaml.safe_load(file)

        # Delete the redundant YAML files.
        _os.remove("input.yaml")
        _os.remove("output.yaml")

        return output
Ejemplo n.º 5
0
def _find_md_package(system, protocol, gpu_support=False):
    """Find a molecular dynamics package on the system and return
       a handle to it as a MDPackage object.

       Parameters
       ----------

       system : :class:`System <BioSimSpace._SireWrappers.System>`
           The molecular system.

       protocol : :class:`Protocol <BioSimSpace.Protocol>`
           The simulation protocol.

       gpu_support : bool
           Whether to use package must have GPU support.

       Returns
       -------

       (package, exe) : (str, str)
           The name of the MD package and a path to its executable.
    """

    # The input has already been validated in the run method, so no need
    # to re-validate here.

    # Get the file format of the molecular system.
    fileformat = system.fileFormat()

    # Make sure that this format is supported.
    if not fileformat in _file_extensions:
        raise ValueError("Cannot find an MD package that supports format: %s" %
                         fileformat)
    else:
        packages = _file_extensions[fileformat]

    # Is this a free energy protocol.
    if type(protocol) is _Protocol.FreeEnergy:
        is_free_energy = True
    else:
        is_free_energy = False

    # Loop over each package that supports the file format.
    for package in packages:
        # If this is free energy protocol, then check that the package has support.
        if not is_free_energy or _free_energy[package]:
            # Check whether this package exists on the system and has the desired
            # GPU support.
            for exe, gpu in _md_packages[package].items():
                # If the user has requested GPU support make sure the package
                # supports it.
                if not gpu_support or gpu:
                    # AMBER
                    if package == "AMBER":
                        # Search AMBERHOME, if set.
                        if _amber_home is not None:
                            _exe = "%s/bin/%s" % (_amber_home, exe)
                            if _os.path.isfile(_exe):
                                return (package, _exe)
                        # Search system PATH.
                        else:
                            try:
                                exe = _SireBase.findExe(exe).absoluteFilePath()
                                return (package, exe)
                            except:
                                pass
                    # GROMACS
                    elif package == "GROMACS":
                        if _gmx_exe is not None:
                            return (package, _gmx_exe)
                    # SOMD
                    elif package == "SOMD":
                        return (package, _SireBase.getBinDir() + "/somd")
                    # Search system PATH.
                    else:
                        try:
                            exe = _SireBase.findExe(exe).absoluteFilePath()
                            return (package, exe)
                        except:
                            pass

    # If we get this far, then no package was found.
    raise _MissingSoftwareError("Couldn't find package to support format: %s" %
                                fileformat)