示例#1
0
    def setUpClass(cls):
        # init project and resource
        import tempfile
        cls.shared_path = tempfile.mkdtemp(prefix="adaptivemd")
        Project.delete('example-simple-1')
        cls.project = Project('example-simple-1')
        # ----------------------------------------------------------------------
        # CREATE THE RESOURCE
        #   the instance to know about the place where we run simulations
        # ----------------------------------------------------------------------
        cls.project.initialize({'shared_path': cls.shared_path})
        if os.getenv('CONDA_BUILD', False):
            # activate the conda build test environment for workers

            cls.f_base = 'examples/files/alanine/'
            prefix = os.getenv('PREFIX')
            assert os.path.exists(prefix)
            cls.project.configuration.wrapper.pre.insert(
                0, 'source activate {prefix}'.format(prefix=prefix))

            # TODO why does test_simple_wrapper not
            #      have a chdir to ci test environment?
            test_tmp = prefix + '/../test_tmp/'
            if os.getcwd() is not test_tmp:
                os.chdir(test_tmp)
        else:
            # set the path for the workers to the path of the test interpreter.
            import sys

            cls.f_base = '../../examples/files/alanine/'
            cls.project.configuration.wrapper.pre.insert(
                0, 'PATH={python_path}:$PATH'.format(
                    python_path=os.path.dirname(sys.executable)))

        return cls
    def setUpClass(cls):
        '''
        Operations that configure the test environment
        ----------------------------------------------

            env :
                    determine if local or in integration environment

            pkg :
                    object imports and coordination

            cfg :
                    object instantiation and building
                    one-time operations that set up for test

        '''

        # init project and resource
        import tempfile
        cls.shared_path = tempfile.mkdtemp(prefix="adaptivemd")
        Project.delete('test-skeleton')
        cls.project = Project('test-skeleton')
        cls.project.initialize({'shared_path': cls.shared_path})
        # ----------------------------------------------------------------------
        # CREATE THE RESOURCE
        #   the instance to know about the place where we run simulations
        # ----------------------------------------------------------------------
        if os.getenv('CONDA_BUILD', False):

            # activate the conda build test environment
            cls.f_base = 'examples/files/alanine/'
            prefix = os.getenv('PREFIX')
            assert os.path.exists(prefix)

            cls.project.configuration.wrapper.pre.insert(
                0, 'source activate {prefix}'.format(prefix=prefix))

            # TODO why does test_simple_wrapped not
            #      have a chdir to ci test environment?
            # TODO this is dealing in relative paths
            #      --> should check cwd based on absolute path
            test_tmp = prefix + '/../test_tmp/'
            if os.getcwd() is not test_tmp:
                os.chdir(test_tmp)

        else:
            # set the path for the workers to the path of the test interpreter.
            import sys

            cls.f_base = '../../examples/files/alanine/'
            cls.project.configuration.wrapper.pre.insert(
                0, 'PATH={python_path}:$PATH'.format(
                    python_path=os.path.dirname(sys.executable)))

        return cls
示例#3
0
def init_project(p_name,
                 sys_name=None,
                 m_freq=None,
                 p_freq=None,
                 platform=None,
                 reinitialize=False):  #, dblocation=None):
    #def init_project(p_name, **freq):

    from adaptivemd import Project

    #if p_name in Project.list():
    #    print("Deleting existing version of this test project")
    #    Project.delete(p_name)

    dburl = os.environ.get("ADMD_DBURL", 0)
    if dburl:
        logger.info("Set ADMD_DBURL to: " + dburl)
        Project.set_dburl(dburl)
# if dblocation is not None:

#     Project.set_dblocation(dblocation)

    if reinitialize:
        logger.info(
            "Project {0} exists, deleting it from database to reinialize".
            format(p_name))
        Project.delete(p_name)

    if p_name in Project.list():
        logger.info(
            "Project {0} exists, reading it from database".format(p_name))
        project = Project(p_name)

    elif not all([sys_name, m_freq, p_freq, platform]):
        raise ValueError(
            "Must define all parameters [{0}] to initialize new project\nHave: {1}"
            .format("sys_name,m_freq,p_freq,platform",
                    [sys_name, m_freq, p_freq, platform].__repr__()))

    else:

        project = Project(p_name)

        from adaptivemd import File, OpenMMEngine
        from adaptivemd.analysis.pyemma import PyEMMAAnalysis

        # Initialize w/ config file: 1 of multiple options
        # TODO add config filename argument
        configuration_file = 'configuration.cfg'
        project.initialize(configuration_file)

        f_name = '{0}.pdb'.format(sys_name)

        # FIXME add system specifications to configuration file
        f_base = 'file:///$ADMD_FILES/{0}/'.format(sys_name)

        f_structure = File(f_base + f_name).load()

        f_system_2 = File(f_base + 'system-2.xml').load()
        f_integrator_2 = File(f_base + 'integrator-2.xml').load()

        f_system_5 = File(f_base + 'system-5.xml').load()
        f_integrator_5 = File(f_base + 'integrator-5.xml').load()

        sim_args = '-r -p {0}'.format(platform)

        engine_2 = OpenMMEngine(f_system_2, f_integrator_2, f_structure,
                                sim_args).named('openmm-2')

        engine_5 = OpenMMEngine(f_system_5, f_integrator_5, f_structure,
                                sim_args).named('openmm-5')

        # FIXME this is dumb and hard for user to deal with
        # TODO engine selection by name
        m_freq_2 = m_freq
        p_freq_2 = p_freq
        m_freq_5 = m_freq * 2 / 5
        p_freq_5 = p_freq * 2 / 5

        engine_2.add_output_type('master', 'allatoms.dcd', stride=m_freq_2)
        engine_2.add_output_type('protein',
                                 'protein.dcd',
                                 stride=p_freq_2,
                                 selection='protein')

        engine_5.add_output_type('master', 'allatoms.dcd', stride=m_freq_5)
        engine_5.add_output_type('protein',
                                 'protein.dcd',
                                 stride=p_freq_5,
                                 selection='protein')

        ca_features = {'add_distances_ca': None}
        #features = {'add_inverse_distances': {'select_Backbone': None}}
        ca_modeller_2 = PyEMMAAnalysis(engine_2, 'protein',
                                       ca_features).named('pyemma-ca-2')

        ca_modeller_5 = PyEMMAAnalysis(engine_5, 'protein',
                                       ca_features).named('pyemma-ca-5')

        pos = [
            '(rescode K and mass > 13) ' + 'or (rescode R and mass > 13) ' +
            'or (rescode H and mass > 13)'
        ]
        neg = ['(rescode D and mass > 13) ' + 'or (rescode E and mass > 13)']

        ionic_features = {
            'add_distances': {
                'select': pos
            },
            'kwargs': {
                'indices2': {
                    'select': neg
                }
            }
        }

        all_features = [ca_features, ionic_features]

        inv_ca_features = {'add_inverse_distances': {'select_Ca': None}}

        #ok#ionic_modeller = {'add_distances': {'select':
        #ok#                                   ['rescode K or rescode R or rescode H']},
        #ok#                  'kwargs': {'indices2': {'select':
        #ok#                                   'rescode D or rescode E']}}}
        #contact_features = [ {'add_inverse_distances':
        #                         {'select_Backbone': None}},
        #                     {'add_residue_mindist': None,
        #                      'kwargs': {'threshold': 0.6}}
        #                   ]

        all_modeller_2 = PyEMMAAnalysis(engine_2, 'protein',
                                        all_features).named('pyemma-ionic-2')

        all_modeller_5 = PyEMMAAnalysis(engine_5, 'protein',
                                        all_features).named('pyemma-ionic-5')

        inv_modeller_2 = PyEMMAAnalysis(
            engine_2, 'protein', inv_ca_features).named('pyemma-invca-2')

        inv_modeller_5 = PyEMMAAnalysis(
            engine_5, 'protein', inv_ca_features).named('pyemma-invca-5')

        project.generators.add(ca_modeller_2)
        project.generators.add(all_modeller_2)
        project.generators.add(inv_modeller_2)
        project.generators.add(ca_modeller_5)
        project.generators.add(all_modeller_5)
        project.generators.add(inv_modeller_5)
        project.generators.add(engine_2)
        project.generators.add(engine_5)

        #[print(g) for g in project.generators]

    return project
示例#4
0
import os

from adaptivemd import Project

from adaptivemd import OpenMMEngine
from adaptivemd import PyEMMAAnalysis

from adaptivemd import File
from adaptivemd import WorkerScheduler

import mdtraj as md

if __name__ == '__main__':

    Project.delete('example-simple-1')
    project = Project('example-simple-1')

    # --------------------------------------------------------------------------
    # CREATE THE RESOURCE
    #   the instance to know about the place where we run simulations
    # --------------------------------------------------------------------------

    project.initialize({'shared_path': '$HOME'})

    # --------------------------------------------------------------------------
    # CREATE THE ENGINE
    #   the instance to create trajectories
    # --------------------------------------------------------------------------

    pdb_file = File('file://../../examples/files/alanine/alanine.pdb').named(
示例#5
0
def init_project(p_name,
                 sys_name,
                 m_freq,
                 p_freq,
                 platform,
                 reinitialize=False):  #, dblocation=None):
    #def init_project(p_name, **freq):

    from adaptivemd import Project

    #if p_name in Project.list():
    #    print("Deleting existing version of this test project")
    #    Project.delete(p_name)

    dburl = os.environ.get("ADMD_DBURL")
    if dburl:
        logger.info("Set ADMD_DBURL to: " + dburl)
        Project.set_dburl(dburl)
# if dblocation is not None:

#     Project.set_dblocation(dblocation)

    if reinitialize:
        logger.info(
            "Project {0} exists, deleting it from database to reinialize".
            format(p_name))

        Project.delete(p_name)

    if p_name in Project.list():

        logger.info(
            "Project {0} exists, reading it from database".format(p_name))

        project = Project(p_name)

    else:

        project = Project(p_name)

        from adaptivemd import File, OpenMMEngine
        from adaptivemd.analysis.pyemma import PyEMMAAnalysis

        #####################################
        # NEW initialize sequence
        configuration_file = 'configuration.cfg'
        project.initialize(configuration_file)
        #
        # OLD initialize sequence
        #from adaptivemd import LocalResource
        #resource = LocalResource('/lustre/atlas/scratch/jrossyra/bip149/admd/')
        #project.initialize(resource)
        #####################################

        f_name = '{0}.pdb'.format(sys_name)

        # only works if filestructure is preserved as described in 'jro_ntl9.ipynb'
        # and something akin to job script in 'admd_workers.pbs' is used
        f_base = 'file:///$ADMDRP_ADAPTIVEMD/examples/files/{0}/'.format(
            sys_name)

        f_structure = File(f_base + f_name).load()

        f_system_2 = File(f_base + 'system-2.xml').load()
        f_integrator_2 = File(f_base + 'integrator-2.xml').load()

        f_system_5 = File(f_base + 'system-5.xml').load()
        f_integrator_5 = File(f_base + 'integrator-5.xml').load()

        sim_args = '-r -p {0}'.format(platform)

        engine_2 = OpenMMEngine(f_system_2, f_integrator_2, f_structure,
                                sim_args).named('openmm-2')

        engine_5 = OpenMMEngine(f_system_5, f_integrator_5, f_structure,
                                sim_args).named('openmm-5')

        m_freq_2 = m_freq
        p_freq_2 = p_freq
        m_freq_5 = m_freq * 2 / 5
        p_freq_5 = p_freq * 2 / 5

        engine_2.add_output_type('master', 'allatoms.dcd', stride=m_freq_2)
        engine_2.add_output_type('protein',
                                 'protein.dcd',
                                 stride=p_freq_2,
                                 selection='protein')

        engine_5.add_output_type('master', 'allatoms.dcd', stride=m_freq_5)
        engine_5.add_output_type('protein',
                                 'protein.dcd',
                                 stride=p_freq_5,
                                 selection='protein')

        ca_features = {'add_distances_ca': None}
        #features = {'add_inverse_distances': {'select_Backbone': None}}
        ca_modeller_2 = PyEMMAAnalysis(engine_2, 'protein',
                                       ca_features).named('pyemma-ca-2')

        ca_modeller_5 = PyEMMAAnalysis(engine_5, 'protein',
                                       ca_features).named('pyemma-ca-5')

        pos = [
            '(rescode K and mass > 13) ' + 'or (rescode R and mass > 13) ' +
            'or (rescode H and mass > 13)'
        ]
        neg = ['(rescode D and mass > 13) ' + 'or (rescode E and mass > 13)']

        ionic_features = {
            'add_distances': {
                'select': pos
            },
            'kwargs': {
                'indices2': {
                    'select': neg
                }
            }
        }

        all_features = [ca_features, ionic_features]

        inv_ca_features = {'add_inverse_distances': {'select_Ca': None}}

        #ok#ionic_modeller = {'add_distances': {'select':
        #ok#                                   ['rescode K or rescode R or rescode H']},
        #ok#                  'kwargs': {'indices2': {'select':
        #ok#                                   'rescode D or rescode E']}}}
        #contact_features = [ {'add_inverse_distances':
        #                         {'select_Backbone': None}},
        #                     {'add_residue_mindist': None,
        #                      'kwargs': {'threshold': 0.6}}
        #                   ]

        all_modeller_2 = PyEMMAAnalysis(engine_2, 'protein',
                                        all_features).named('pyemma-ionic-2')

        all_modeller_5 = PyEMMAAnalysis(engine_5, 'protein',
                                        all_features).named('pyemma-ionic-5')

        inv_modeller_2 = PyEMMAAnalysis(
            engine_2, 'protein', inv_ca_features).named('pyemma-invca-2')

        inv_modeller_5 = PyEMMAAnalysis(
            engine_5, 'protein', inv_ca_features).named('pyemma-invca-5')

        project.generators.add(ca_modeller_2)
        project.generators.add(all_modeller_2)
        project.generators.add(inv_modeller_2)
        project.generators.add(ca_modeller_5)
        project.generators.add(all_modeller_5)
        project.generators.add(inv_modeller_5)
        project.generators.add(engine_2)
        project.generators.add(engine_5)

        #[print(g) for g in project.generators]

    return project