Exemple #1
0
    def test_raise_OSError(self):

        with mock.patch("HPC_Drug.auxiliary_functions.path.which",
                        side_effect=OSError,
                        autospec=True):

            with mock.patch(
                    "HPC_Drug.auxiliary_functions.path.absolute_filepath",
                    side_effect=FileNotFoundError,
                    autospec=True):

                with self.assertRaises(OSError):

                    path.absolute_programpath(program="test")
Exemple #2
0
    def _plumed_partial_tempering(self, scaling_value, input_file, output_file):
        """
        private

        Creates the scaled topology files with plumed
        """

        plumed = path.absolute_programpath(program = "plumed")

        command = [plumed, "partial_tempering", f"{scaling_value}"]

        print(f"Running Plumed, with scaling value {scaling_value}")

        with open(input_file, "r") as input_file_handle:
            with open(output_file, "w") as output_file_handle:
                
                r = subprocess.run(command,
                                shell = False,
                                stdin = input_file_handle,
                                stdout= output_file_handle,
                                stderr= subprocess.PIPE)

        print(r.stderr)

        if r.returncode != 0:
            raise RuntimeError(f"Plumed failure\n{r.stderr}")
Exemple #3
0
    def __init__(self,
                 Protein,
                 solvent_box,
                 MD_program_path='orac',
                 number_of_cores_per_node=64,
                 number_of_replicas=8):

        self.Protein = Protein

        self.solvent_box = solvent_box

        self.MD_program_path = path.absolute_programpath(
            program=MD_program_path)

        self.number_of_cores_per_node = number_of_cores_per_node

        self.orac_in_file = f"HREM.in"

        #dummy useless value
        self.kind_of_processor = 'skylake'

        #an instance of orient.Orient class
        self.orient = orient.Orient(self.Protein,
                                    self.Protein.get_ligand_list())

        self.BATTERIES = self._get_BATTERIES()

        self.replicas = number_of_replicas
Exemple #4
0
    def test_use_which(self):

        with mock.patch("HPC_Drug.auxiliary_functions.path.which",
                        return_value="test_output",
                        autospec=True) as mocked_function:

            output = path.absolute_programpath(program="test")

            mocked_function.assert_called_once_with(program="test")

            self.assertEqual(output, "test_output")
Exemple #5
0
    def __init__(self, Protein=None, MD_program_path='gmx'):

        self.Protein = Protein

        self.output_gro_file = os.getcwd(
        ) + f"{self.Protein.protein_id}_gromacs.gro"

        self.output_pdb_file = os.getcwd(
        ) + f"{self.Protein.protein_id}_gromacs.pdb"

        self.mdp_file = os.getcwd() + f"/{self.Protein.protein_id}_gromacs.mdp"

        self.MD_program_path = path.absolute_programpath(
            program=MD_program_path)

        self.command_string = []

        self.template = []
    def __init__(self, Protein, solvent_pdb=None, MD_program_path='orac'):
        """
        Protein :: HPC_Drug.structures.protein.Protein instance

        solvent_pdb :: string, it is the pdb file that contains the coordinates of a solvent molecule 
        it is needed if there has to be added a solvent box around the protein 
        default HPC_Drug.lib "water.pdb"

        MD_program_path :: string, the absolute path to the orac executable 
        dafault will look for an executable called orac in the PATH and the working directory (in this order)
        """

        self.Protein = Protein

        self.orac_in_file = os.getcwd() + f"/{self.Protein.protein_id}_orac.in"

        self.solvent_pdb = solvent_pdb
        #if no path is given searches the standard water.pdb inside lib module
        if self.solvent_pdb == None:
            with importlib_resources.path('HPC_Drug.lib',
                                          'water.pdb') as _path:
                self.solvent_pdb = str(_path.resolve())

        self.MD_program_path = path.absolute_programpath(
            program=MD_program_path)

        self.output_pdb_file = os.getcwd(
        ) + f"/{self.Protein.protein_id}_orac.pdb"

        #an instance of orient.Orient class
        self.orient = orient.Orient(self.Protein,
                                    self.Protein.get_ligand_list())

        self.template = []

        #some values that are needed many times are calculated in the constructor

        #The box sizes (lx, ly, lz)
        #the structure is rotated in its tensor of inertia ref
        self.box = self._create_selfbox()
def get_topology(Protein, program_path, tool="primadorac", ph=7.0):
    """
    uses the right tool to get
    the topology of a given organic ligand (.itp .tpg .prm etc...)
    in order to use it in a MD run
    returns the updated protein

    Protein :: HPC_Drug.structures.protein.Protein instance
    with a valid Protein._ligands (Protein.get_ligand_list())
    value (if it is None or [] will return the protein untouched)

    program_path :: string, the absolute path to the tool's executable

    tool :: string, default primadorac, the tool to use to get the
    topology (.itp .tpg .prm etc...)

    ph :: float, default 7.0, the ph at which the ligand shall be added the missing hydrogens

    return Protein
    """

    if Protein.get_ligand_list() == None or Protein.get_ligand_list() == []:
        return Protein

    program_path = path.absolute_programpath(program=program_path)

    if tool == "primadorac":

        primadorac_obj = primadorac.Primadorac(Protein=Protein,
                                               primadorac_path=program_path,
                                               ph=ph)

        Protein = primadorac_obj.execute()

    else:

        raise NotImplementedError(f"{tool} is not an implemented tool")

    return Protein
Exemple #8
0
    def _refine_input(self, input_variables = None):

        """Makes the needed casts from string, defines some None to default ecc"""

        # Protein_model must be an integer
        if input_variables['Protein_model'] != None:
            input_variables['Protein_model'] = int(input_variables['Protein_model'])
        #default is zero
        elif input_variables['Protein_model'] == None:
            input_variables['Protein_model'] = 0

        #The standard chain is 'A'
        if input_variables['Protein_chain'] == None:
            input_variables['Protein_chain'] = 'A'
        #need it uppercase
        else:
            input_variables['Protein_chain'] = input_variables['Protein_chain'].upper().strip()

        #ph must be a float
        if input_variables['ph'] != None:
            input_variables['ph'] = float(input_variables['ph'])
        
        #sets primadorac as the default ligand elaboration program and tries to guess where the executable is
        if input_variables['ligand_elaboration_program'] == None:
            input_variables['ligand_elaboration_program'] = 'primadorac'
        
        if input_variables['ligand_elaboration_program_path'] == None:
            input_variables['ligand_elaboration_program_path'] = program_path.absolute_programpath(program = '~/ORAC/trunk/tools/primadorac/primadorac.bash')
        else:
            input_variables['ligand_elaboration_program_path'] = program_path.absolute_programpath(program = input_variables['ligand_elaboration_program_path'])

        #absolute path of the program path
        input_variables['MD_program_path'] = program_path.absolute_programpath(program = input_variables['MD_program_path'])


        if input_variables['MD_program'] == None:
            input_variables['MD_program'] = 'gromacs'

        if input_variables['MD_program'] == 'orac':
            if input_variables['protein_tpg_file'] == None:
                with importlib_resources.path('HPC_Drug.lib', 'amber99sb-ildn.tpg') as path:
                    input_variables['protein_tpg_file'] = str(path.resolve())
            
            if input_variables['protein_prm_file'] == None:
                with importlib_resources.path('HPC_Drug.lib', 'amber99sb-ildn.prm') as path:
                    input_variables['protein_prm_file'] = str(path.resolve())

            if input_variables['solvent_pdb'] == None:
                with importlib_resources.path('HPC_Drug.lib', 'water.pdb') as path:
                    input_variables['solvent_pdb'] = str(path.resolve())
        
        elif input_variables['MD_program'] == 'gromacs':
            if input_variables['protein_tpg_file'] == None:
                input_variables['protein_tpg_file'] = 'amber99sb-ildn'

            if input_variables['solvent_pdb'] == None:
                input_variables['solvent_pdb'] = 'spce'


        #set a default for processor (skylake)
        if input_variables['kind_of_processor'] == None:
            input_variables['kind_of_processor'] = 'skylake'
        
        else:
            #in this way I don't have to worry about strange input formats
            input_variables['kind_of_processor'] = input_variables['kind_of_processor'].lower().strip()

        #the number of cores per node is usually 64
        if input_variables['number_of_cores_per_node'] == None:
            input_variables['number_of_cores_per_node'] = 64
        
        else:
            #cast string to integer
            input_variables['number_of_cores_per_node'] = int(input_variables['number_of_cores_per_node'].strip())

        
        if input_variables['residue_substitution'] == None:
            input_variables['residue_substitution'] = 'standard'

        if input_variables['use_gpu'] == None:
            input_variables['use_gpu'] = 'auto'

        if input_variables['gpu_per_node'] is None:
            input_variables['gpu_per_node'] = 1
        
        else:
            input_variables['gpu_per_node'] = int(input_variables['gpu_per_node'])

        if input_variables['number_of_hrem_replicas_per_battery_bound'] is None:
            input_variables['number_of_hrem_replicas_per_battery_bound'] = 8

        elif input_variables['number_of_hrem_replicas_per_battery_bound'] == 0 or input_variables['number_of_hrem_replicas_per_battery_bound'] == 1:
            raise ValueError("The number of bound HREM replicas must be greater than 1")

        else:
            input_variables['number_of_hrem_replicas_per_battery_bound'] = int(input_variables['number_of_hrem_replicas_per_battery_bound'].strip())
        

        if input_variables['number_of_hrem_replicas_per_battery_unbound'] is None:
            input_variables['number_of_hrem_replicas_per_battery_unbound'] = 8

        elif input_variables['number_of_hrem_replicas_per_battery_unbound'] == 0 or input_variables['number_of_hrem_replicas_per_battery_unbound'] == 1:
            raise ValueError("The number of bound HREM replicas must be greater than 1")

        else:
            input_variables['number_of_hrem_replicas_per_battery_unbound'] = int(input_variables['number_of_hrem_replicas_per_battery_unbound'].strip())

        for i in ('bound_batteries', 'unbound_batteries', 'n_steps_bound_hrem', 'n_steps_unbound_hrem'):

            if input_variables[i] == 'auto':

                input_variables[i] = None

            elif input_variables[i] is not None:

                input_variables[i] = int(input_variables[i])

        for i in ('timestep_bound_hrem', 'timestep_unbound_hrem'):

            if input_variables[i] == 'auto':

                input_variables[i] = None

            elif input_variables[i] is not None:

                input_variables[i] = float(input_variables[i])

        for i in ('constraints_bound_hrem', 'constraints_unbound_hrem'):

            if input_variables[i] == 'auto':

                input_variables[i] = None

        if input_variables['box_borders'] is not None:

            input_variables['box_borders'] = float(input_variables['box_borders'])


        if input_variables['repairing_method'].lower() == 'none':
            input_variables['repairing_method'] = False
        
        return input_variables
    "The number of alchemical transformations to do, a good default is 200 protein ligand and 400 ligand only, default=200"
)

parser.add_argument(
    '--constrains',
    action="store",
    default=None,
    type=str,
    choices=['none', 'h-bonds', 'all-bonds'],
    help=
    "how to constraints vibrations, same syntax as gromacs mdp file default=all-bonds"
)

parsed_input = parser.parse_args()

parsed_input.program_path = path.absolute_programpath(
    parsed_input.program_path)

if parsed_input.hrem_type == "protein-ligand":

    creation = False

elif parsed_input.hrem_type == "only-ligand":

    creation = True

# From comma separated list to list of int
parsed_input.pbc_atoms = parsed_input.pbc_atoms.split(',')
for i, atom in enumerate(parsed_input.pbc_atoms):
    parsed_input.pbc_atoms[i] = int(atom)

fsdam_obj = fsdam.FSDAMInputPreprocessing(