Example #1
0
def loadTrainInfo(item,
                  modProt,
                  modProtVer,
                  modelDir=settings.get('etoxlie_model_dir')):
    protVer = '%04d' % modProtVer
    pathParams = os.path.join(modelDir, modProt, protVer, 'params.pkl')
    if os.path.exists(pathParams):
        with open(pathParams, 'r') as inFile:
            parms = pickle.load(inFile)

        trainSet = parms[item]

    else:
        return (False, 'Model parameters not found (%s)' % pathParams)

    return (True, trainSet)
Example #2
0
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with eTOXlab.  If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import logging
from time import sleep

from eTOX_ALLIES.etox import settings
from eTOX_ALLIES.etox.core import jobHandler
from eTOX_ALLIES.etox.core.main import submitScreen, screenSDF

etoxlie_folder = settings.get('etoxlie_folder')


class imodel():
    def __init__(self, vpath, jobid='<not defined>'):
        """
        LIE settings
        
        The jobid argument was added by Marc van Dijk, 21-10-2016.
        It passes along the Celery job identifier responsible for 
        launching this calculation from the etoxwsapi side of things.
        This API jobid is stored in the .dsr and .job files greated
        by eTOXLie and enables API job cancelation by querying for 
        the jobid and touching an empty KILL file in the associated
        eTOXlie job directory.
        """
Example #3
0
def prepareMD(wdir,itpLig,pdbLig, proteinPoses,model,dirSimPref='sim',localExe=True,timeSim=1.0,\
              scriptExe='lie_mdrun.sh',enePref='MD_ene', decPref='decomp',remoteSettings=None):
    currDir = os.getcwd()

    try:
        topology = importlib.import_module("eTOX_ALLIES.etox.topology.%s" %
                                           model['forceField'])
    except Exception, e:
        logging.error('Error in loading module "{0}": {1}'.format(
            model['forceField'], e))
        sys.exit()

    listFiles = []

    GMXMD = os.path.join(settings.get('etoxlie_root_dir'), 'bin/gmx45md.sh')
    ENERGYANALYSIS = os.path.join(settings.get('etoxlie_root_dir'),
                                  'bin/getEnergies.py')
    GMXRC = settings.get('GMXRC')

    listFiles.extend([GMXMD, ENERGYANALYSIS])
    os.chdir(wdir)

    #Fix topology ligand
    itpOut = 'compound_ref.itp'
    success, results = topology.correctItp(itpLig, itpOut, posre=True)

    listFiles.append(results['itp'])  # Ligand itp
    if 'posre' in results:
        listFiles.append(results['posre'])  # ligand posre
Example #4
0
if os.name == 'posix' and sys.version_info[0] < 3:
    import subprocess32 as sp
else:
    import subprocess as sp

import pybel as pb
import openbabel as ob
from glob import glob

from eTOX_ALLIES.etox import settings
from eTOX_ALLIES.etox.core import modelHandler
from eTOX_ALLIES.etox.topology.amber import refineTau
from eTOX_ALLIES.etox.core.geometry import findOcpd1, normhem, distance as dist

AMBERHOME = settings.get('AMBERHOME')
ACPYPE = settings.get('ACPYPE')
DATADIR = os.path.join(settings.get('etoxlie_root_dir'), 'bin/files/')
GROMACSHOME = settings.get('GROMACSHOME')

ob.obErrorLog.SetOutputLevel(0)


def prepareModel(modelDir, modelData, etoxlie_folder, radiusRes=16):
    '''modelData={name: str, dockSoftware: str, timeSim: float, forceField:str, resSite: None or list
                  pH: float, pHCorr: bool, protConfs: list of dictionaries }
        protConfs: [{'pdb' : str, 'center' : None / [X,Y,Z], 'radius' : float }]
    '''

    currDir = os.getcwd()
    success = True
Example #5
0
def linkElab(keyElab='ETOXLABHOME', overWrite=True):
    eLabFn = 'imodel.py'
    eLabVersions = 'service-version.txt'
    eLabLabel = 'service-label.txt'
    #Get list calibrated models
    listModels = modelHandler.listModels(modelDir)

    eLabDir = settings.get(keyElab)
    if not os.path.isdir(str(eLabDir)):
        msg = 'Specified folder in settings.py does not exists: {0}'.format(
            eLabDir)
        logging.error(msg)
        return (False, msg)

    try:
        for model in listModels:
            ### Create service-label.txt; service-version.txt; models dir
            modDir = os.path.join(eLabDir, model['name'])
            if not os.path.isdir(modDir):
                os.mkdir(modDir)

            outFn = os.path.join(modDir, eLabVersions)
            outFileVers = open(outFn, 'w')
            # For eTOXlab compatibility
            fakever = 'version%04d' % 0
            modDirVer = os.path.join(modDir, fakever)
            if not os.path.isdir(modDirVer):
                os.mkdir(modDirVer)
            outFileVers.write('0\t0\n')

            for version in model['vers']:
                vers = 'version%04d' % version
                modDirVer = os.path.join(modDir, vers)
                if not os.path.isdir(modDirVer):
                    os.mkdir(modDirVer)
                outFn = os.path.join(modDirVer, eLabFn)

                sourceTmpl = getsource(
                    importlib.import_module("etox.core.imodel"))
                sourceTmpl = sourceTmpl.replace('REPLACE_PROTEIN',
                                                model['name'])
                sourceTmpl = sourceTmpl.replace('REPLACE_VERSION',
                                                str(model['vers'][0]))

                if os.path.exists(outFn):
                    logging.info('%s is already present in %s' %
                                 (eLabFn, modDirVer))
                    if not overWrite:
                        logging.warn('%s/%s will not be overwrite' %
                                     (modDirVer, eLabFn))
                        continue
                with open(outFn, 'w') as outFile:
                    outFile.write(sourceTmpl)

                outFileVers.write('%d\t0\n' % version)

            outFileVers.close()
            ### Versioning and labelling services
            # full tag: e.g. /ADME/Metabolism/Phase I/CYP 1A2 Affinity/1
            outFn = os.path.join(modDir, eLabLabel)
            with open(outFn, 'w') as outFile:
                outFile.write('/ADME/Metabolism/Phase I/%s Affinity/1\n' %
                              model['name'])
                outFile.write('quantitative')

    except exception, e:
        return (False, e)
Example #6
0
import os, sys
import importlib
from inspect import getsource

from eTOX_ALLIES.etox import settings
from eTOX_ALLIES.etox.core import modelHandler

modelDir = settings.get('etoxlie_model_dir')


def linkElab(keyElab='ETOXLABHOME', overWrite=True):
    eLabFn = 'imodel.py'
    eLabVersions = 'service-version.txt'
    eLabLabel = 'service-label.txt'
    #Get list calibrated models
    listModels = modelHandler.listModels(modelDir)

    eLabDir = settings.get(keyElab)
    if not os.path.isdir(str(eLabDir)):
        msg = 'Specified folder in settings.py does not exists: {0}'.format(
            eLabDir)
        logging.error(msg)
        return (False, msg)

    try:
        for model in listModels:
            ### Create service-label.txt; service-version.txt; models dir
            modDir = os.path.join(eLabDir, model['name'])
            if not os.path.isdir(modDir):
                os.mkdir(modDir)
Example #7
0
                        default=None)
    parser.add_argument('-o',
                        '--output',
                        dest='outPref',
                        required=False,
                        default='')

    args = parser.parse_args()

    logging.basicConfig(level='DEBUG')

    if args.job and args.model:
        logging.error(
            'Analysis of a job or a model cannot be done simultaneously')
        sys.exit(1)

    if args.job is not None:
        extractJob(args.job,
                   settings.get('tmpFolder'),
                   settings.get('etoxlie_model_dir'),
                   outPref=args.outPref)

    if args.model is not None:
        try:
            ver = int(args.version)
        except:
            logging.error('A model version should be provide "e.g. -v 1"')
            sys.exit(1)

        extractModel(args.model, ver, modelDir)
Example #8
0
import logging
import pybel as pb
import openbabel as ob
import time
import numpy as np

from eTOX_ALLIES.etox import settings
from eTOX_ALLIES.etox.core import jobHandler
from eTOX_ALLIES.etox.core.modelHandler import loadModel, saveModel, listModels
from eTOX_ALLIES.etox.core.docking import dockLie
from eTOX_ALLIES.etox.core.MDrunner import *
from eTOX_ALLIES.etox.core.utility_lie import calibrateLie, predictLie, predictError
from eTOX_ALLIES.etox.core.utility_AD import calibrateAD, predictAD

etoxlie_folder = settings.get('etoxlie_folder')
modelDir = settings.get('etoxlie_model_dir')
statEndJob = ['FAILED', 'CANCELLED', 'DONE']


def protonate(sdf, fileOut, pHcorr=True, pH=7.5):
    '''If necessary converts the 2D structure of the molecule to 3D and protonation by pybel/openbabel
    input:
        sdf: sdf file as string
        neutral: boolean; if molecule should be protonate according to pH is False
        pH: pH for protonation 
    the result is a tuple containing:
        1)  True/False: describes the success of the operation
        2)  (if True ) The name of the 3D molecule
            (if False) The error message
    '''