Example #1
0
    def launch(self) -> int:
        """Execute the :class:`Mutate <model.mutate.Mutate>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        # Create command line
        self.cmd = [self.check_structure_path,
                    '-i', self.stage_io_dict["in"]["input_pdb_path"],
                    '-o', self.stage_io_dict["out"]["output_pdb_path"],
                    'mutateside', '--mut', self.mutation_list]

        if self.use_modeller:
            if modeller_installed(self.out_log, self.global_log):
                self.cmd.append('--rebuild')
            else:
                fu.log(f"Modeller is not installed --rebuild option can not be used proceeding without using it",
                       self.out_log, self.global_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        # Remove temporal files
        self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
        self.remove_tmp_files()

        return self.return_code
Example #2
0
def check_in_path(path, out_log, classname):
    """ Checks input instructions file """
    if not Path(path).exists():
        fu.log(classname + ': Unexisting input instructions file, exiting',
               out_log)
        raise SystemExit(classname + ': Unexisting input instructions file')

    # check syntax for instructions file
    syntax_instructions = True
    err_instructions = ''
    if not 'parm ' in open(path).read():
        syntax_instructions = False
        err_instructions += 'No topology provided'
    if not 'trajin ' in open(path).read():
        syntax_instructions = False
        err_instructions += ' No input trajectory provided'
    if not syntax_instructions:
        fu.log(
            classname +
            ': Incorrect syntax for instructions file: %s, exiting' %
            err_instructions, out_log)
        raise SystemExit(
            classname +
            ': Incorrect syntax for instructions file: %s, exiting' %
            err_instructions)
Example #3
0
def get_end(properties, out_log, classname):
    """ Gets end """
    end = properties.get('end', get_default_value('end'))
    if not is_valid_int(end):
        fu.log(classname + ': Incorrect end provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect end provided')
    return str(end)
Example #4
0
    def launch(self):
        """Launches the execution of the Open Babel module."""
        
        # Get local loggers from launchlogger decorator
        out_log = getattr(self, 'out_log', None)
        err_log = getattr(self, 'err_log', None)

        # check input/output paths and parameters
        self.check_data_params(out_log, err_log)

        # Check the properties
        fu.check_properties(self, self.properties)

        if self.restart:
            output_file_list = [self.output_path_par, self.output_path_inp, self.output_path_top]
            if fu.check_complete_files(output_file_list):
                fu.log('Restart is enabled, this step: %s will the skipped' % self.step, out_log, self.global_log)
                return 0

        # create unique name for temporary folder (created by acpype)
        self.unique_name = create_unique_name(6)

        # create command line instruction
        cmd = self.create_cmd(out_log, err_log) 

        # execute cmd
        fu.log('Running %s, this execution can take a while' % self.acpype_path, out_log)
        returncode = cmd_wrapper.CmdWrapper(cmd, out_log, err_log, self.global_log).launch()
        # move files to output_path and removes temporary folder
        process_output(self.unique_name, self.basename + "." + self.unique_name + ".acpype", self.remove_tmp, self.basename, get_default_value(self.__class__.__name__), self.output_files, out_log)
        return returncode
Example #5
0
def get_parameters(properties, type, classname, out_log):
    """ Gets in_parameters and out_parameters """
    if not properties.get(type, dict()):
        fu.log('No %s parameters provided' % type, out_log)
        return get_default_value(classname)[type]

    return {k: v for k, v in properties.get(type, dict()).items()}
Example #6
0
def get_fit(properties, out_log, classname):
    """ Gets fit """
    fit = properties.get('fit', get_default_value('fit'))
    if not is_valid_fit(fit):
        fu.log(classname + ': Incorrect fit provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect fit provided')
    return fit
Example #7
0
def get_start(properties, out_log, classname):
    """ Gets start """
    start = properties.get('start', get_default_value('start'))
    if not is_valid_int(start):
        fu.log(classname + ': Incorrect start provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect start provided')
    return str(start)
Example #8
0
def get_center(properties, out_log, classname):
    """ Gets center """
    center = properties.get('center', get_default_value('center'))
    if not is_valid_boolean(center):
        fu.log(classname + ': Incorrect center provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect center provided')
    return center
Example #9
0
def get_ur(properties, out_log, classname):
    """ Gets ur """
    ur = properties.get('ur', get_default_value('ur'))
    if not is_valid_ur(ur):
        fu.log(classname + ': Incorrect ur provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect ur provided')
    return ur
Example #10
0
def process_output_gmx(unique_name, files_folder, remove_tmp, basename,
                       class_params, output_files, out_log):
    """ Moves and removes temporal files generated by the wrapper """
    path = files_folder
    suffix = class_params['suffix']
    src_files = glob.glob(path + '/' + basename + '.' + unique_name + suffix +
                          '*')

    # copy files for the requested topology to the output_path
    for file_name in src_files:
        # replace random name by original name in all files
        with fileinput.FileInput(file_name, inplace=True) as file:
            for line in file:
                print(line.replace(basename + '.' + unique_name, basename),
                      end='')

        if (Path(file_name).is_file()):
            file_extension = PurePath(file_name).suffix
            # in top files for gromacs, replace file.itp by name given by user
            if (file_extension[1:] == 'top'):
                with open(file_name) as f:
                    newText = f.read().replace(
                        basename + '_GMX.itp',
                        PurePath(output_files['itp']).name)
                with open(file_name, "w") as f:
                    f.write(newText)
            shutil.copy(file_name, output_files[file_extension[1:]])
            fu.log(
                'File %s succesfully created' %
                output_files[file_extension[1:]], out_log)

    if remove_tmp:
        # remove temporary folder
        fu.rm(files_folder)
        fu.log('Removed temporary folder: %s' % files_folder, out_log)
Example #11
0
def get_pbc(properties, out_log, classname):
    """ Gets pbc """
    pbc = properties.get('pbc', get_default_value('pbc'))
    if not is_valid_pbc(pbc):
        fu.log(classname + ': Incorrect pbc provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect pbc provided')
    return pbc
Example #12
0
def process_output(unique_name, files_folder, remove_tmp, basename,
                   class_params, output_files, out_log):
    """ Moves and removes temporal files generated by the wrapper """
    path = files_folder
    suffix = class_params['suffix']
    src_files = glob.glob(path + '/' + basename + '.' + unique_name + suffix +
                          '*')

    # copy files for the requested topology to the output_path
    for file_name in src_files:
        # replace random name by original name in all files
        with fileinput.FileInput(file_name, inplace=True) as file:
            for line in file:
                print(line.replace(basename + '.' + unique_name, basename),
                      end='')

        if (Path(file_name).is_file()):
            file_extension = PurePath(file_name).suffix
            shutil.copy(file_name, output_files[file_extension[1:]])
            fu.log(
                'File %s succesfully created' %
                output_files[file_extension[1:]], out_log)

    if remove_tmp:
        # remove temporary folder
        fu.rm(files_folder)
        fu.log('Removed temporary folder: %s' % files_folder, out_log)
Example #13
0
def check_mandatory_property(property, name, out_log, classname):
    """ Checks mandatory properties """

    if not property:
        fu.log(classname + ': Unexisting %s property, exiting' % name, out_log)
        raise SystemExit(classname + ': Unexisting %s property' % name)
    return property
Example #14
0
def get_memprotmd_sim_search(collection_name,
                             keyword,
                             out_log=None,
                             global_log=None):
    """ Performs advanced searches in the MemProtMD DB using its REST API and a given keyword """

    fu.log(
        'Getting search results from the MemProtMD REST API. Collection name: %s, keyword: %s'
        % (collection_name, keyword), out_log, global_log)

    url = "http://memprotmd.bioch.ox.ac.uk/api/search/advanced"
    json_query = {
        "collectionName": collection_name,
        "query": {
            "keywords": keyword
        },
        "projection": {
            "simulations": 1
        },
        "options": {}
    }

    json_obj = requests.post(url, json=json_query).json()
    json_string = json.dumps(json_obj, indent=4)

    # get total number of simulation
    list_kw = []
    for sim_list in json_obj:
        for sim in sim_list['simulations']:
            list_kw.append(sim)

    fu.log('Total number of simulations: %d' % (len(list_kw)), out_log,
           global_log)

    return json_string
Example #15
0
def get_dt(properties, out_log, classname):
    """ Gets dt """
    dt = properties.get('dt', get_default_value('dt'))
    if not is_valid_int(dt):
        fu.log(classname + ': Incorrect dt provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect dt provided')
    return str(dt)
Example #16
0
def get_xvg(properties, out_log, classname):
    """ Gets xvg """
    xvg = properties.get('xvg', get_default_value('xvg'))
    if not is_valid_xvg_param(xvg):
        fu.log(classname + ': Incorrect xvg provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect xvg provided')
    return xvg
Example #17
0
    def launch(self) -> int:
        """Execute the :class:`PdbClusterZip <api.pdb_cluster_zip.PdbClusterZip>` api.pdb_cluster_zip.PdbClusterZip object."""
        
        # check input/output paths and parameters
        self.check_data_params(self.out_log, self.err_log)

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        check_mandatory_property(self.pdb_code, 'pdb_code', self.out_log, self.__class__.__name__)

        self.pdb_code = self.pdb_code.strip().lower()

        file_list = []
        #Downloading PDB_files
        pdb_code_list = get_cluster_pdb_codes(pdb_code=self.pdb_code, cluster=self.cluster, out_log=self.out_log, global_log=self.global_log)
        unique_dir = fu.create_unique_dir()
        for pdb_code in pdb_code_list:
            pdb_file = os.path.join(unique_dir, pdb_code+".pdb")
            pdb_string = download_pdb(pdb_code=pdb_code, api_id=self.api_id, out_log=self.out_log, global_log=self.global_log)
            write_pdb(pdb_string, pdb_file, self.filter, self.out_log, self.global_log)
            file_list.append(os.path.abspath(pdb_file))

        #Zipping files
        fu.log("Zipping the pdb files to: %s" % self.output_pdb_zip_path)
        fu.zip_list(self.output_pdb_zip_path, file_list, out_log=self.out_log)

        if self.remove_tmp:
            # remove temporary folder
            fu.rm(unique_dir)
            fu.log('Removed temporary folder: %s' % unique_dir, self.out_log)

        return 0
Example #18
0
    def launch(self) -> int:
        """Execute the :class:`ApiBindingSite <api.api_binding_site.ApiBindingSite>` api.api_binding_site.ApiBindingSite object."""

        # check input/output paths and parameters
        self.check_data_params(self.out_log, self.err_log)

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        check_mandatory_property(self.pdb_code, 'pdb_code', self.out_log,
                                 self.__class__.__name__)

        self.pdb_code = self.pdb_code.strip().lower()
        url = "https://www.ebi.ac.uk/pdbe/api/pdb/entry/binding_sites/%s"

        # get JSON object
        json_string = download_binding_site(self.pdb_code, url, self.out_log,
                                            self.global_log)

        # get number of binding sites
        fu.log(
            '%d binding sites found' %
            (len(json.loads(json_string)[self.pdb_code])), self.out_log,
            self.global_log)

        # write JSON file
        write_json(json_string, self.output_json_path, self.out_log,
                   self.global_log)

        return 0
Example #19
0
def get_cutoff(properties, out_log, classname):
    """ Gets cutoff """
    cutoff = properties.get('cutoff', get_default_value('cutoff'))
    if not is_valid_float(cutoff):
        fu.log(classname + ': Incorrect cutoff provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect cutoff provided')
    return str(cutoff)
Example #20
0
def process_output_fpocket_filter(search_list, tmp_folder, input_pockets_zip,
                                  output_filter_pockets_zip, remove_tmp,
                                  out_log):
    """ Creates the output_filter_pockets_zip """

    # decompress the input_pockets_zip file to tmp_folder
    cluster_list = fu.unzip_list(zip_file=input_pockets_zip,
                                 dest_dir=tmp_folder,
                                 out_log=out_log)

    # list all files of tmp_folder
    pockets_list = [str(i) for i in Path(tmp_folder).iterdir()]

    # select search_list items from pockets_list
    sel_pockets_list = [
        p for p in pockets_list for s in search_list if s + '_' in p
    ]

    fu.log('Creating %s output file' % output_filter_pockets_zip, out_log)

    # compress output to output_filter_pockets_zip
    fu.zip_list(zip_file=output_filter_pockets_zip,
                file_list=sel_pockets_list,
                out_log=out_log)

    if remove_tmp:
        # remove temporary folder
        fu.rm(tmp_folder)
        fu.log('Removed temporary folder: %s' % tmp_folder, out_log)
Example #21
0
def get_method(properties, out_log, classname):
    """ Gets method """
    method = properties.get('method', get_default_value('method'))
    if not is_valid_method_param(method):
        fu.log(classname + ': Incorrect method provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect method provided')
    return method
Example #22
0
def get_dista(properties, out_log, classname):
    """ Gets dista """
    dista = properties.get('dista', get_default_value('dista'))
    if not is_valid_boolean(dista):
        fu.log(classname + ': Incorrect dista provided, exiting', out_log)
        raise SystemExit(classname + ': Incorrect dista provided')
    return dista
Example #23
0
    def launch(self) -> int:
        """Execute the :class:`Gmxselect <gromacs.gmxselect.Gmxselect>` object."""

        # Setup Biobb
        if self.check_restart(): return 0
        self.stage_files()

        self.cmd = [
            self.gmx_path, 'select', '-s',
            self.stage_io_dict["in"]["input_structure_path"], '-on',
            self.stage_io_dict["out"]["output_ndx_path"]
        ]

        if self.stage_io_dict["in"].get("input_ndx_path") and Path(
                self.stage_io_dict["in"].get("input_ndx_path")).exists():
            self.cmd.append('-n')
            self.cmd.append(self.stage_io_dict["in"].get("input_ndx_path"))

        self.cmd.append('-select')
        self.cmd.append("\'" + self.selection + "\'")

        if self.gmx_lib:
            self.environment = os.environ.copy()
            self.environment['GMXLIB'] = self.gmx_lib

        # Check GROMACS version
        if not self.container_path:
            if self.gmx_version < 512:
                raise GromacsVersionError(
                    "Gromacs version should be 5.1.2 or newer %d detected" %
                    self.gmx_version)
            fu.log(
                "GROMACS %s %d version detected" %
                (self.__class__.__name__, self.gmx_version), self.out_log)

        # Run Biobb block
        self.run_biobb()

        # Copy files to host
        self.copy_to_host()

        if self.io_dict["in"].get("input_ndx_path"):
            if self.append:
                fu.log(
                    f"Appending {self.io_dict['in'].get('input_ndx_path')} to {self.io_dict['out']['output_ndx_path']}",
                    self.out_log, self.global_log)
                with open(self.io_dict["out"]["output_ndx_path"],
                          'a') as out_ndx_file:
                    out_ndx_file.write('\n')
                    with open(self.io_dict["in"].get(
                            "input_ndx_path")) as in_ndx_file:
                        for line in in_ndx_file:
                            out_ndx_file.write(line)

        # Remove temporal files
        self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
        self.remove_tmp_files()

        return self.return_code
Example #24
0
def write_mmcif(mmcif_string,
                output_mmcif_path,
                out_log=None,
                global_log=None):
    """ Writes a mmcif """
    fu.log("Writting mmcif to: %s" % (output_mmcif_path), out_log, global_log)
    with open(output_mmcif_path, 'w') as output_mmcif_file:
        output_mmcif_file.write(mmcif_string)
Example #25
0
def getWeight(weight, data, out_log, classname):
    if 'index' in weight:
        return data.iloc[:, weight['index']]
    elif 'column' in weight:
        return data[weight['column']]
    else:
        fu.log(classname + ': Incorrect weight format', out_log)
        raise SystemExit(classname + ': Incorrect weight format')
Example #26
0
def getTarget(target, data, out_log, classname):
    if 'index' in target:
        return data.iloc[:, target['index']]
    elif 'column' in target:
        return data[target['column']]
    else:
        fu.log(classname + ': Incorrect target format', out_log)
        raise SystemExit(classname + ': Incorrect target format')
Example #27
0
def checkResamplingType(type_, out_log, classname):
    """ Gets resampling type """
    if not type_:
        fu.log(classname + ': Missed mandatory type property', out_log)
        raise SystemExit(classname + ': Missed mandatory type property')
    if type_ != 'regression' and type_ != 'classification':
        fu.log(classname + ': Unknown %s type property' % type_, out_log)
        raise SystemExit(classname + ': Unknown %s type property' % type_)
Example #28
0
def get_ph(p, out_log):
	""" Checks if provided coordinates value is correct """
	ph = str(p)
	if p and not isinstance(p, float) and not isinstance(p, int):
		ph = ''
		fu.log('Incorrect format for pH, no value assigned', out_log)

	return ph
Example #29
0
def get_coordinates(coordinates, out_log):
	""" Checks if provided coordinates value is correct """
	crd = str(coordinates)
	if crd != '3' and crd != '2':
		fu.log('Value %s is not compatible as a coordinates value' % crd, out_log)
		crd = ''

	return crd
Example #30
0
def write_fasta(fasta_string,
                output_fasta_path,
                out_log=None,
                global_log=None):
    """ Writes a FASTA """
    fu.log("Writting FASTA to: %s" % (output_fasta_path), out_log, global_log)
    with open(output_fasta_path, 'w') as output_fasta_file:
        output_fasta_file.write(fasta_string)