Ejemplo n.º 1
0
    def plants_docking(self, request, claims):
        """
        Perform a PLANTS (Protein-Ligand ANT System) molecular docking.
        For a detail description of the input see the file:
        schemas/endpoints/docking-request.v1.json
        """

        # Validate input path_file object for protein and ligand file
        protein_file = mol_validate_file_object(request['protein_file'])
        ligand_file = mol_validate_file_object(request['ligand_file'])

        # Run docking
        base_dir = os.environ.get('BASE_WORK_DIR', request.get('base_work_dir'))

        for drop_key in ('protein_file', 'ligand_file', 'base_work_dir'):
            if drop_key in request:
                del request[drop_key]

        docking = PlantsDocking(log=self.log, base_work_dir=base_dir, **request)

        if docking.run(protein_file['content'], ligand_file['content']):
            return {'status': 'completed', 'result': docking.get_results()}

        self.log.error('PLANTS docking failed')
        return {'status': 'failed'}
Ejemplo n.º 2
0
    def smartcyp_prediction(self, request, claims):
        """
        Run a SMARTCyp prediction for a molecule

        :param request:
        :param claims:
        :return:
        """

        # Validate input path_file object for mol
        ligand_file = mol_validate_file_object(request['ligand_file'])

        # Run smartcyp
        base_dir = os.environ.get('BASE_WORK_DIR', request.get('base_work_dir'))
        smartcyp = SmartCypRunner(log=self.log, base_work_dir=base_dir)
        result_dict = smartcyp.run(ligand_file['content'],
                                   is_smiles=ligand_file['extension'] == 'smi',
                                   output_format=request['output_format'],
                                   noempcorr=request['noempcorr'])

        # Remove temporary working directory
        smartcyp.delete()

        result_dict['status'] = 'completed' if result_dict['result'] is not None else 'failed'
        return result_dict
Ejemplo n.º 3
0
def smartcyp_prediction(ligand_file=None,
                        smiles=None,
                        output_format='json',
                        noempcorr=False,
                        output_png=False):
    """
    Run a REST based SMARTCyp prediction for a molecule

    :param ligand_file:   molecule to make prediction for
    :type ligand_file:    :py:str
    :param smiles:        molecule as SMILES or InChI string
    :type smiles:         :py:str
    :param output_format: output format as CSV, JSON or HTML
    :type output_format:  :py:str
    :param noempcorr:     do not use the empirical N-oxidation correction
                          (smartcyp >= v2.3)
    :type noempcorr:      :py:bool
    :param output_png:    export PNG image files for the prediction

    :return:              SMARTCyp results as JSON, CSV or HTML
    :rtype:               :py:str
    """

    # Input molecule is either a SMILES/InChI string or file object
    path_file_object = {
        'content': smiles,
        'extension': 'smi' if smiles else None,
        'path': None
    }
    if isinstance(ligand_file, FileStorage):
        path_file_object['content'] = ligand_file.read().decode('utf-8')
        if '.' in os.path.basename(ligand_file.filename):
            path_file_object['extension'] = ligand_file.filename.split('.')[-1]
        path_file_object['path'] = ligand_file.filename

    if path_file_object['content'] is None:
        return "Ligand input from file 'mol' or as 'smiles' string required", 401

    # Validate path_file_object: valid SMILES or InChI strings
    path_file_object = mol_validate_file_object(path_file_object)

    # Run SMARTCyp
    smartcyp = SmartCypRunner()
    try:
        result_dict = smartcyp.run(
            path_file_object['content'],
            is_smiles=path_file_object['extension'] == 'smi',
            input_format=path_file_object.get('extension', 'mol2'),
            output_format=output_format,
            noempcorr=noempcorr,
            output_png=output_png)
    except Exception as e:
        return str(e), 500
    finally:
        smartcyp.delete()

    return result_dict
Ejemplo n.º 4
0
    def som_prediction(self, request, claims):
        """
        Run a REST based SOM prediction run
        """

        # Validate input path_file object for protein and ligand file
        ligand_file = mol_validate_file_object(request['ligand_file'])

        # Run combined structure/reactivity prediction
        base_dir = os.environ.get('BASE_WORK_DIR', request.get('base_work_dir'))
        sompred = CombinedPrediction(base_work_dir=base_dir, **request)
        prediction = sompred.run(ligand_file, filter_clusters=request['filter_clusters'])

        if prediction:
            return {'status': 'completed', 'output': prediction}

        self.log.error('SOM prediction failed')
        return {'status': 'failed'}
Ejemplo n.º 5
0
    def spores_run(self, request, claims):
        """
        Perform a SPORES (Structure PrOtonation and REcognition System) structure preparation.
        For a detail description of the input see the file:
        schemas/endpoints/spores-request.v1.json
        """

        # Validate input path_file object for mol
        mol = mol_validate_file_object(request['mol'])

        spores = SporesRunner(log=self.log, base_work_dir=os.environ.get('BASE_WORK_DIR', request.get('base_work_dir')))
        try:
            result_dict = spores.run(mol['content'], mode=request['spores_mode'], input_format=request['input_format'])
        except Exception as e:
            self.log.error(str(e))
            return {'status': 'failed'}
        finally:
            spores.delete()

        return {'status': 'completed', 'result': result_dict}