Ejemplo n.º 1
0
def main():

    #Check settings file exist?
    dataController = DataController()
    dataController.checkExist()

    ViLASApp().run()
Ejemplo n.º 2
0
class RemoveDialog(Popup):

    gromacsRun = GromacsRun()
    thread = ObjectProperty(None)
    dataController = DataController()

    def cancel(self):
        self.dismiss()
        self.thread = Process(target=self.gromacsRun.main)
        self.thread.start()
        pass

    def remove(self):
        self.dismiss()
        call('rm -r ' + self.dataController.getdata('path ') + '/run/*',
             shell=True)
        call('rm -r ' + self.dataController.getdata('path ') +
             '/output/ligand/*',
             shell=True)
        call('rm -r ' + self.dataController.getdata('path ') +
             '/output/receptor/*',
             shell=True)
        self.thread = Process(target=self.gromacsRun.main)
        self.thread.start()
        pass

    pass
Ejemplo n.º 3
0
class FinishDialog(Popup):
    dialogText = ObjectProperty(None)

    def setText(self, dialog_text):
        self.dialogText.text = dialog_text

    gromacsRun = GromacsRun()
    thread = ObjectProperty(None)
    dataController = DataController()

    def cancel(self):
        self.dismiss()
        pass

    # def remove(self):
    #     self.dismiss()
    #     App().stop()
    #     # App.get_running_app().stop()
    #     pass

    pass
Ejemplo n.º 4
0
class ConfigurationScreen(Screen):
    root_path = os.path.dirname(__file__)

    dataController = DataController()

    optimizedButton = ObjectProperty(None)
    customButton = ObjectProperty(None)
    OptimizedButton = ObjectProperty(None)
    optimizedTick = ObjectProperty(None)
    configLayout = ObjectProperty(None)
    boxGromacs = ObjectProperty(None)
    versionButton = ObjectProperty(None)
    is_optimized = True

    pathText = ObjectProperty(None)
    caverBox = ObjectProperty(None)
    icstBox = ObjectProperty(None)
    ligandAutoBox = ObjectProperty(None)
    repeatTimesText = ObjectProperty(None)
    nohupBox = ObjectProperty(None)
    configpBox = ObjectProperty(None)
    normalBox = ObjectProperty(None)
    maximumCoresText = ObjectProperty(None)
    gpuAutoBox = ObjectProperty(None)


    def setupView(self):
        dropdown = DropDown()

        #Check gromacs version 
        try:
            command_version = check_output("compgen -ac | grep mdrun", shell=True, executable='/bin/bash').splitlines()
            for x in range(0, len(command_version)):
                print command_version[x]
                try:
                    versions = check_output(str(command_version[x])+" -version", shell=True, executable='/bin/bash').splitlines()
                    if not any("Gromacs version" in s for s in versions):
                        continue
                    version = [s for s in versions if "Gromacs version" in s][0].split(":")[1]
                    btn = Button(text=str(command_version[x]) + version, size_hint_y=None, height=35)
                    btn.bind(on_release=lambda btn: dropdown.select(btn.text))
                    # then add the button inside the dropdown
                    dropdown.add_widget(btn)
                    #Set first gromacs found
                    if x == 0 and self.dataController.getdata('gromacs_version ') == '':
                        self.versionButton.text = str(command_version[x]) + version
                        self.dataController.setdata('gromacs_version ', str(command_version[x] + version))
                    if self.dataController.getdata('gromacs_version ') == str(command_version[x]) + version:
                        self.versionButton.text = str(command_version[x]) + version
                except subprocess.CalledProcessError as e:
                    print e
        except subprocess.CalledProcessError as e:
            print e

        try:
            gmx_version = check_output("compgen -ac | grep gmx", shell=True, executable='/bin/bash').splitlines()
            for x in range(0, len(gmx_version)):
                print gmx_version[x]
                try:
                    versions = check_output(str(gmx_version[x])+" -version", shell=True, executable='/bin/bash').splitlines()
                    if not any("GROMACS version" in s for s in versions):
                        continue
                    version = [s for s in versions if "GROMACS version" in s][0].split(":")[1]
                    numVers = version.split('VERSION')[1].replace(' ','').split('.')
                    # If version >= 5.1
                    if int(numVers[0]) == 5 and int(numVers[1])>0:
                        btn = Button(text=str(gmx_version[x]) + version, size_hint_y=None, height=35)
                        btn.bind(on_release=lambda btn: dropdown.select(btn.text))
                        # then add the button inside the dropdown
                        dropdown.add_widget(btn)

                        #Set first gromacs found
                        if self.dataController.getdata('gromacs_version ') == '':
                            self.versionButton.text = str(gmx_version[x]) + version
                            self.dataController.setdata('gromacs_version ', str(gmx_version[x] + version))
                        if self.dataController.getdata('gromacs_version ') == str(gmx_version[x]) + version:
                            self.versionButton.text = str(gmx_version[x]) + version
                except subprocess.CalledProcessError as e:
                    print e
        except subprocess.CalledProcessError as e:
            print e
        
        self.versionButton.bind(on_release=dropdown.open)
        dropdown.bind(on_select=self.gromacs_version_check)

        #Check number of cores
        command_cores = check_output("nproc", shell=True, executable='/bin/bash').splitlines()
        if(len(command_cores) > 0):
            self.dataController.setdata('maximum_cores ', command_cores[0])
            self.maximumCoresText.text = command_cores[0]

    def __init__(self, *args, **kwargs):
        super(ConfigurationScreen, self).__init__(*args, **kwargs)        

        if ( self.dataController.getdata('config_auto ') == 'True' ):
            self.configLayout.disabled = True
        else: 
            # Disable touch = false
            self.configLayout.disabled = False
            # Set color of button
            self.is_optimized = False
            self.optimizedTick.color = [1,1,1,0]
            self.customTick.color = [1,1,1,1]
            self.optimizedButton.background_color = [0.62, 0.62, 0.62, 1]
            self.customButton.background_color = [0, 0.588, 0.533, 1]

        # Set init value for config
        self.pathText.text = self.dataController.getdata('path ')

        if (self.dataController.getdata('caver') == 'True'):
            self.caverBox.active = True
        else:
            self.caverBox.active = False

        if (self.dataController.getdata('icst') == 'True'):
            self.icstBox.active = True
        else:
            self.icstBox.active = False

        if (self.dataController.getdata('ligand_auto') == 'True'):
            self.ligandAutoBox.active = True
        else:
            self.ligandAutoBox.active = False

        self.repeatTimesText.text = self.dataController.getdata('repeat_times')

        self.nohupBox.active = False
        self.configBox.active = False
        self.normalBox.active = False
        if (self.dataController.getdata('mode') == 'nohup'):
            self.nohupBox.active = True
        elif(self.dataController.getdata('mode') == 'config'):
            self.configBox.active = True
        else:
            self.normalBox.active = True
            # self.dataController.setdata('mode', 'normal')



        self.maximumCoresText.text = self.dataController.getdata('maximum_cores')

        if (self.dataController.getdata('gpu_auto') == 'True'):
            self.gpuAutoBox.active = True
        else:
            self.gpuAutoBox.active = False


        # set listener
        self.pathText.bind(text = self.path_change)
        self.caverBox.bind(active = self.caver_check)
        self.icstBox.bind(active = self.icst_check)
        self.ligandAutoBox.bind(active = self.ligand_auto_check)
        self.repeatTimesText.bind(text = self.repeat_times)
        self.nohupBox.bind(active = self.nohup_check)
        self.configBox.bind(active = self.config_check)
        self.normalBox.bind(active = self.normal_check)
        self.maximumCoresText.bind(text = self.maximum_cores)
        self.gpuAutoBox.bind(active = self.gpu_auto_check)


    def path_change(self, instance, value):
        self.dataController.setdata('path ', value)
        
    def caver_check(self, checkbox, value):
        self.dataController.setdata('caver', str(value))
        #self.dataController.setdata('icst', str(not value))

    def icst_check(self, checkbox, value):
        self.dataController.setdata('icst', str(value))
        #self.dataController.setdata('caver', str(not value))

    def ligand_auto_check(self, checkbox, value):
        self.dataController.setdata('ligand_auto', str(value))

    def repeat_times(self, instance, value):
        self.dataController.setdata('repeat_times ', value)

    def nohup_check(self, checkbox, value):
        if value == True:
            self.dataController.setdata('mode ', 'nohup')
    def config_check(self, checkbox, value):
        if value == True:
            self.dataController.setdata('mode ', 'config')
    def normal_check(self, checkbox, value):
        if value == True:
            self.dataController.setdata('mode ', 'normal')

    def maximum_cores(self, instance, value):
        self.dataController.setdata('maximum_cores ', value)

    def gpu_auto_check(self, checkbox, value):
        self.dataController.setdata('gpu_auto ', str(value))

    def gromacs_version_check(self, instance, value):
        self.dataController.setdata('gromacs_version ', str(value))
        self.versionButton.text = value

    # For 2 button
    def optimizedConfig(self):
        if (self.is_optimized == True):
            pass
        else:
            self.is_optimized = True
            self.optimizedTick.color = [1,1,1,1]
            self.customTick.color = [1,1,1,0]
            self.optimizedButton.background_color = [0, 0.588, 0.533, 1]
            self.customButton.background_color = [0.62, 0.62, 0.62, 1]

            self.configLayout.disabled = True
            self.dataController.setdata('config_auto ', 'True')


    def customConfig(self):
        if (self.is_optimized == True):
            self.is_optimized = False
            self.optimizedTick.color = [1,1,1,0]
            self.customTick.color = [1,1,1,1]
            self.optimizedButton.background_color = [0.62, 0.62, 0.62, 1]
            self.customButton.background_color = [0, 0.588, 0.533, 1]

            self.configLayout.disabled = False
            self.dataController.setdata('config_auto ', 'False')
        else:
            pass

    pass
Ejemplo n.º 5
0
class RunningScreen(Screen):
    root_path = os.path.dirname(__file__)
    dataController = DataController()

    pymol = ObjectProperty(None)
    progressBar = ObjectProperty(None)
    checkFile = ObjectProperty(None)
    emImg = ObjectProperty(None)
    nvtImg = ObjectProperty(None)
    nptImg = ObjectProperty(None)
    mdImg = ObjectProperty(None)
    smdImg = ObjectProperty(None)
    smdLog = ObjectProperty(None)
    progressText = ObjectProperty(None)
    progressLayout = ObjectProperty(None)
    progressImage = ObjectProperty(None)

    progressUnit = 0
    progressPoint = 0

    checkPOINT = ''
    checkEM = False
    checkNVT = False
    checkNPT = False
    checkMD = False
    checkSMD = False
    lastSMD = 0
    angle = 0
    firstFinish = True
    lastFinish = False

    GroLeft = ''
    GroRight = ''
    GroVersion = ''

    #Create thread to run background
    gromacsRun = GromacsRun()
    thread = ObjectProperty(None)

    def __init__(self, *args, **kwargs):
        super(RunningScreen, self).__init__(*args, **kwargs)

        # init progress image
        self.progressImage = ProgressImage()
        self.progressLayout.add_widget(self.progressImage)
        pass

    def set_pymol(self, pym):
        self.pymol = pym

    def setupView(self):
        # Check gromacs version
        self.checkGromacVersion()

        #Check if folder is exits
        call('mkdir ' + self.dataController.getdata('path '), shell=True)
        call('mkdir ' + self.dataController.getdata('path ') + '/run',
             shell=True)
        call('mkdir ' + self.dataController.getdata('path ') + '/output',
             shell=True)
        call('mkdir ' + self.dataController.getdata('path ') +
             '/output/receptor',
             shell=True)
        call('mkdir ' + self.dataController.getdata('path ') +
             '/output/ligand',
             shell=True)
        call('mkdir ' + self.dataController.getdata('path ') + '/analyse',
             shell=True)

        runfolders = check_output(
            'ls ' + self.dataController.getdata('path ') + '/run/',
            shell=True).splitlines()
        if len(runfolders) > 0:
            popup = RemoveDialog()
            popup.open()
        else:
            call('rm -r ' + self.dataController.getdata('path ') + '/run/*',
                 shell=True)
            call('rm -r ' + self.dataController.getdata('path ') +
                 '/output/ligand/*',
                 shell=True)
            call('rm -r ' + self.dataController.getdata('path ') +
                 '/output/receptor/*',
                 shell=True)
            self.thread = Process(target=self.gromacsRun.main)
            self.thread.start()

        #Check log
        repeat_times = int(self.dataController.getdata('repeat_times '))
        self.progressUnit = 1000 / (4.5 + repeat_times) / len(
            Variable.parsepdb.Ligands)
        self.progressPoint = 0
        self.dataController.setdata('status', '')
        Clock.schedule_interval(self.check_log, 5)
        Clock.schedule_interval(self.spin_progress, 0.05)
        # Clock.schedule_interval(self.pymol_log, 300)

        #close pymol
        self.pymol.cmd.window('hide')

    def spin_progress(self, dt):
        if self.dataController.getdata('status') != 'finished':
            if (self.angle == 360):
                self.angle = 0
            self.angle += 10
            self.progressImage.rot.angle = self.angle
            self.progressImage.rot.origin = self.progressImage.center
            self.progressImage.rot.axis = (0, 0, 1)
        # self.progressImage.canvas.add(Rotate(angle=(self.angle), origin=(self.progressImage.center)))

    def check_log(self, dt):
        if self.dataController.getdata('status') == 'finished':
            if self.lastFinish == False:
                self.lastFinish = True
                popup = FinishDialog()
                popup.setText(
                    'Your job is finished. \n \nNow, you can close the interface. '
                )
                popup.open()
                self.progressText.text = 'Labpi finished your jobs! now you can close app.'
                self.checkFile.text = str(
                    self.dataController.getdata('status'))

        elif self.dataController.getdata('status') != '':
            # Check run nohup finish app
            if (self.dataController.getdata('mode ') == 'nohup'
                    and self.firstFinish == True):
                self.firstFinish = False
                popup = FinishDialog()
                popup.setText(
                    'Your job is running in background. \n \nNow, you can close the interface. '
                )
                popup.open()

            run_path = str(
                self.dataController.getdata('path ')) + '/run/' + str(
                    self.dataController.getdata('status'))
            repeat_times = int(self.dataController.getdata('repeat_times '))

            if self.checkPOINT == '':
                self.checkPOINT = str(self.dataController.getdata('status'))
            elif self.checkPOINT != str(self.dataController.getdata('status')):
                self.checkEM = checkNVT = checkNPT = checkMD = checkSMD = True
                self.lastSMD = 0
                self.checkPOINT = str(self.dataController.getdata('status'))

            em_path = run_path + '/em.gro'
            if os.path.isfile(em_path) == True:
                self.emImg.source = self.root_path + '/img/tick_select.png'
                if self.checkEM == False:
                    self.checkEM = True
                    self.progressPoint += self.progressUnit * 0.5
                    self.progressText.text = 'Labpi is running at NVT step'
            else:
                self.emImg.source = self.root_path + '/img/tick_normal.png'
                self.progressText.text = 'Labpi is running at Energy minimization step'
            # self.emImg.reload()

            nvt_path = run_path + '/nvt.gro'
            if os.path.isfile(nvt_path) == True:
                self.nvtImg.source = self.root_path + '/img/tick_select.png'
                if self.checkNVT == False:
                    self.checkNVT = True
                    self.progressPoint += self.progressUnit * 0.5
                    self.progressText.text = 'Labpi is running at NPT step'
            else:
                self.nvtImg.source = self.root_path + '/img/tick_normal.png'
            # self.nvtImg.reload()

            npt_path = run_path + '/npt.gro'
            if os.path.isfile(npt_path) == True:
                self.nptImg.source = self.root_path + '/img/tick_select.png'
                if self.checkNPT == False:
                    self.checkNPT = True
                    self.progressPoint += self.progressUnit * 0.5
                    self.progressText.text = 'Labpi is running at MD step'
            else:
                self.nptImg.source = self.root_path + '/img/tick_normal.png'
            # self.nptImg.reload()

            md_path = run_path + '/md.gro'
            if os.path.isfile(md_path) == True:
                self.mdImg.source = self.root_path + '/img/tick_select.png'
                if self.checkMD == False:
                    self.checkMD = True
                    self.progressPoint += self.progressUnit
                    self.progressText.text = 'Labpi is running at SMD step'
            else:
                self.mdImg.source = self.root_path + '/img/tick_normal.png'
            # self.mdImg.reload()

            # TODO: check percent import signal
            smd_log = 0
            for x in range(0, int(repeat_times)):
                smd_path_x = run_path + '/md_st_' + str(x) + '.gro'
                if os.path.isfile(smd_path_x) == True:
                    smd_log += 1
                    if self.lastSMD < x:
                        self.lastSMD = x
                        self.checkSMD = False

                    if self.checkSMD == False:
                        self.checkSMD = True
                        self.progressPoint += self.progressUnit
            self.smdLog.text = str(smd_log) + '/' + str(repeat_times)

            smd_path_last = run_path + '/md_st_' + str(repeat_times -
                                                       1) + '.gro'
            if os.path.isfile(smd_path_last) == True:
                self.smdImg.source = self.root_path + '/img/tick_select.png'
            else:
                self.smdImg.source = self.root_path + '/img/tick_normal.png'
            # self.smdImg.reload()

            self.progressBar.value = self.progressPoint
            self.checkFile.text = str(self.dataController.getdata('status'))

    def pymol_log(self, dt):
        if self.dataController.getdata(
                'status') == '' or self.dataController.getdata(
                    'status') == 'finished':
            return

        run_folder = self.dataController.getdata('status')
        run_path = str(
            self.dataController.getdata('path ')) + '/run/' + run_folder
        ligand_name = run_folder.split('run_')[1]
        repeat_times = int(self.dataController.getdata('repeat_times '))

        # Check point for pymol
        check_path = ''
        if os.path.isfile(run_path + '/em.gro') == False and os.path.isfile(
                run_path +
                '/em.cpt') == True and os.path.isfile(run_path +
                                                      '/em.tpr') == True:
            check_path = run_path + '/em'
        if os.path.isfile(run_path + '/nvt.gro') == False and os.path.isfile(
                run_path +
                '/nvt.cpt') == True and os.path.isfile(run_path +
                                                       '/nvt.tpr') == True:
            check_path = run_path + '/nvt'
        if os.path.isfile(run_path + '/npt.gro') == False and os.path.isfile(
                run_path +
                '/npt.cpt') == True and os.path.isfile(run_path +
                                                       '/npt.tpr') == True:
            check_path = run_path + '/npt'
        if os.path.isfile(run_path + '/md.gro') == False and os.path.isfile(
                run_path +
                '/md.cpt') == True and os.path.isfile(run_path +
                                                      '/md.tpr') == True:
            check_path = run_path + '/md'
        if os.path.isfile(run_path + '/md_st.gro') == False and os.path.isfile(
                run_path +
                '/md_st.cpt') == True and os.path.isfile(run_path +
                                                         '/md_st.tpr') == True:
            check_path = run_path + '/md_st'
        for x in range(0, int(repeat_times)):
            if os.path.isfile(run_path + '/md_st_' + str(x) +
                              '.gro') == False and os.path.isfile(
                                  run_path + '/md_st_' + str(x) +
                                  '.cpt') == True and os.path.isfile(
                                      run_path + '/md_st_' + str(x) +
                                      '.tpr') == True:
                check_path = run_path + '/md_st_' + str(x)

        if (check_path != ''):
            call('echo \"non-Water\"|' + self.GroLeft + 'trjconv' +
                 self.GroRight + '-f ' + check_path + '.cpt -s ' + check_path +
                 '.tpr -o ' + check_path + '.pdb',
                 shell=True)
            self.pymol.cmd.reinitialize()
            self.pymol.cmd.load(check_path + '.pdb')

            chains = ParsePdb().listChain(check_path + '.pdb')
            for chain in chains:
                if chain.chain_type == 'protein':
                    self.pymol.cmd.show_as('cartoon', str(chain.chain_view))
                    self.pymol.cmd.cartoon('automatic', str(chain.chain_view))
                else:
                    self.pymol.cmd.show_as(
                        'sticks',
                        'resname ' + str(chain.chain_view.getResnames()[0]))
            # self.pymol.cmd.set('stick_color', 'red')
            self.pymol.util.cbc()
        pass

    def checkGromacVersion(self):
        gromacs_version = self.dataController.getdata('gromacs_version ')
        version_array = gromacs_version.split(' VERSION ')[1].split('.')
        print version_array
        # If version >= 5
        if int(version_array[0]) == 5:
            # If version >= 5.1
            if int(version_array[1]) > 0:
                self.GroLeft = gromacs_version.split(' VERSION ')[0]
                self.GroRight = ''
            else:
                # Check gmx
                mdrun_array = gromacs_version.split(' VERSION ')[0].split(
                    'mdrun')
                self.GroLeft = 'gmx '
                self.GroRight = mdrun_array[1]

            self.GroVersion = 5
        # If version = 4
        else:
            mdrun_array = gromacs_version.split(' VERSION ')[0].split('mdrun')
            self.GroLeft = mdrun_array[0]
            self.GroRight = mdrun_array[1]
            self.GroVersion = 4
Ejemplo n.º 6
0
class GromacsMD(object):
    dataController = DataController()
    # Get version of gromacs
    GroLeft = ''
    GroRight = ''
    GroVersion = ''
    GroOption = ''
    repeat_times = 0

    def mdrun(self):
        main_path = self.dataController.getdata('path ')
        runfolders = check_output('ls ' + main_path + '/run',
                                  shell=True).splitlines()
        call('rm -r ' + main_path + '/analyse/*/', shell=True)

        for x in range(0, len(runfolders)):
            run_path = main_path + '/run/' + runfolders[x]

            if not os.path.isdir(main_path + '/run/' + runfolders[x]):
                continue

            if os.path.isfile(run_path + '/solv_ions.gro') is False:
                continue

            #create folder for analyse
            call('mkdir ' + self.dataController.getdata('path ') +
                 '/analyse/' + runfolders[x].split('_')[1],
                 shell=True)

            # Check point to show log
            self.dataController.setdata('status', runfolders[x])

            run_path = main_path + '/run/' + runfolders[x]
            ligandCurrent = runfolders[x].split('_')[1]  #A01

            print self.GroLeft + 'mdrun' + self.GroRight + ' ' + self.GroOption
            groCmd = ''

            #Run em
            call('mkdir ' + run_path + '/em', shell=True)
            if os.path.isfile(run_path + '/em/em.gro') is False:
                groCmd += self.GroLeft + 'grompp' + self.GroRight + ' -maxwarn 20 -f mdp/minim.mdp -c solv_ions.gro -p topol.top -o em/em.tpr \n'
                groCmd += self.GroLeft + 'mdrun' + self.GroRight + ' ' + self.GroOption + ' -v -deffnm em/em -cpt 5\n'

            #Run nvt
            call('mkdir ' + run_path + '/nvt', shell=True)
            if os.path.isfile(run_path + '/nvt/nvt.gro') is False:
                groCmd += self.GroLeft + 'grompp' + self.GroRight + ' -maxwarn 20 -f mdp/nvt.mdp -c em/em.gro -p topol.top -n index.ndx -o nvt/nvt.tpr \n'
                groCmd += self.GroLeft + 'mdrun' + self.GroRight + ' ' + self.GroOption + ' -deffnm nvt/nvt -v -cpt 5\n'

            #Run npt
            call('mkdir ' + run_path + '/npt', shell=True)
            if os.path.isfile(run_path + '/npt/npt.gro') is False:
                groCmd += self.GroLeft + 'grompp' + self.GroRight + ' -maxwarn 20 -f mdp/npt.mdp -c nvt/nvt.gro -t nvt/nvt.cpt -p topol.top -n index.ndx -o npt/npt.tpr \n'
                groCmd += self.GroLeft + 'mdrun' + self.GroRight + ' ' + self.GroOption + ' -deffnm npt/npt -v -cpt 5\n'

            #Run md
            call('mkdir ' + run_path + '/md', shell=True)
            if os.path.isfile(run_path + '/md/md.gro') is False:
                groCmd += self.GroLeft + 'grompp' + self.GroRight + ' -maxwarn 20 -f mdp/md.mdp -c npt/npt.gro -t npt/npt.cpt -p topol.top -n index.ndx -o md/md.tpr \n'
                groCmd += self.GroLeft + 'mdrun' + self.GroRight + ' ' + self.GroOption + ' -deffnm md/md -v -cpt 5\n'
            groCmd += 'echo -e \"System\"|' + self.GroLeft + 'trjconv' + self.GroRight + ' -s md/md.tpr -f md/md.xtc -o md/md_noPBC.xtc -pbc mol -ur compact\n'
            if (self.GroVersion >= 5):
                groCmd += 'echo -e \"Backbone\\nBackbone\"|' + self.GroLeft + 'rms' + self.GroRight + ' -s md/md.tpr -f md/md_noPBC.xtc -o md/rmsd.xvg -tu ns\n'
            else:
                groCmd += 'echo -e \"Backbone\\nBackbone\"|' + 'g_rms' + self.GroRight + ' -s md/md.tpr -f md/md_noPBC.xtc -o md/rmsd.xvg -tu ns\n'

            # if int(Method) == 1:
            # if (int(self.repeat_times) == 1 or int(self.repeat_times) == 0 ):
            # 	if(self.GroVersion >= 5):
            # 		self.replaceLine('pull-group2-name', 'pull-group2-name     = '+ligandCurrent+'\n', run_path+'/mdp/md_pull_5.mdp')
            # 		groCmd += self.GroLeft+'grompp'+self.GroRight+ ' -maxwarn 20 -f mdp/md_pull_5.mdp -c md.gro -t md.cpt -p topol.top -n index.ndx -o md_st.tpr \n'
            # 	else:
            # 		self.replaceLine('pull_group1', 'pull_group1     = '+ligandCurrent+'\n', run_path+'/mdp/md_pull.mdp')
            # 		groCmd += self.GroLeft+'grompp'+self.GroRight+ ' -maxwarn 20 -f mdp/md_pull.mdp -c md.gro -t md.cpt -p topol.top -n index.ndx -o md_st.tpr \n'

            # 	groCmd += self.GroLeft+'mdrun'+self.GroRight+ ' '+self.GroOption+ ' -px pullx.xvg -pf pullf.xvg -deffnm md_1 -v -cpt 5\n'
            # 	groCmd += 'python2.7 parse_pull.py -x pullx.xvg -f pullf.xvg -o pullfx.xvg\n'

            # else:
            # Repeat the steered for times

            analyse_path = main_path + '/analyse/' + runfolders[x].split(
                '_')[1]
            pull_vec = self.dataController.getdata('smd-vel ')
            pullx_path = ''
            pullf_path = ''
            call('mkdir ' + run_path + '/smd', shell=True)
            for k in range(1, int(self.repeat_times) + 1):
                if os.path.isfile(run_path + '/smd/md_st_' + str(k) +
                                  '.gro') is False:
                    groCmd += self.GroLeft + 'grompp' + self.GroRight + ' -maxwarn 20 -f mdp/md_pull_repeat.mdp -c md/md.gro -t md/md.cpt -p topol.top -n index.ndx -o smd/md_st_' + str(
                        k) + '.tpr \n'
                    groCmd += self.GroLeft + 'mdrun' + self.GroRight + ' ' + self.GroOption + ' -px smd/pullx_' + str(
                        k) + '.xvg -pf smd/pullf_' + str(
                            k) + '.xvg -deffnm smd/md_st_' + str(
                                k) + ' -v -cpt 5\n'
                    groCmd += 'python2.7 parse_pull.py -x smd/pullx_' + str(
                        k) + '.xvg -f smd/pullf_' + str(
                            k) + '.xvg -o smd/pullfx_' + str(k) + '.xvg\n'

                pullx_path += ' smd/pullx_' + str(k) + '.xvg'
                pullf_path += ' smd/pullf_' + str(k) + '.xvg'
            groCmd += 'python2.7 pullana.py -px ' + pullx_path + ' -pf ' + pullf_path + ' -plot ' + analyse_path + '/pull_force_time.png ' + analyse_path + '/pull_force_distance.png -log ' + analyse_path + '/pull_data.csv -v ' + pull_vec + '\n'
            groCmd += 'python2.7 mathplot.py -i md/rmsd.xvg -o ' + analyse_path + '/rmsd.png\n'
            # analyze cmd
            cmd_analyze = 'python2.7 LabpiAnalyzer.py --gro ' + run_path + '/md/md.gro --trj ' + run_path + '/md/md.xtc --mdp ' + run_path + '/mdp/md.mdp --tpr ' + run_path + '/md/md.tpr --start 0 --end 20 --receptor Receptor --ligand ' + ligandCurrent + ' --run ' + run_path + ' --analyze ' + main_path + '/analyse '
            if self.GroLeft.replace(' ', '') != '':
                cmd_analyze += ' --gleft ' + self.GroLeft
            if self.GroRight.replace(' ', '') != '':
                cmd_analyze += ' --gright ' + self.GroRight
            groCmd += cmd_analyze + ' -i False\n'
            # elif int(Method) == 2:
            #   if os.path.isfile(run_path+'/md_2.gro') is False:
            #     groCmd += GroLeft+'grompp'+GroRight+ ' -maxwarn 20 -f mdp/md_md.mdp -c md.gro -t md.cpt -p topol.top -n index.ndx -o md_2.tpr \n'
            #     groCmd += GroLeft+'mdrun'+GroRight+ ' '+GroOption+ ' -deffnm md_2 -v \n'

            #   groCmd += 'export OMP_NUM_THREADS=4\n'
            #   groCmd += 'echo -e \"Receptor\\n'+ligandCurrent+'\\n\" | g_mmpbsa -f md_2.trr -b 100 -dt 20 -s md_2.tpr -n index.ndx -pdie 2 -decomp \n'
            #   groCmd += 'echo -e \"Receptor\\n'+ligandCurrent+'\\n\" | g_mmpbsa -f md_2.trr -b 100 -dt 20 -s md_2.tpr -n index.ndx -i mdp/polar.mdp -nomme -pbsa -decomp \n'
            #   groCmd += 'echo -e \"Receptor\\n'+ligandCurrent+'\\n\" | g_mmpbsa -f md_2.trr -b 100 -dt 20 -s md_2.tpr -n index.ndx -i mdp/apolar_sasa.mdp -nomme -pbsa -decomp -apol sasa.xvg -apcon sasa_contrib.dat \n'
            #   groCmd += 'python2.7 MmPbSaStat.py -m energy_MM.xvg -p polar.xvg -a sasa.xvg \n'

            self.CallCommand(run_path, groCmd)
            # print groCmd

        call('rm -r ' + run_path + '/#*', shell=True)
        self.dataController.setdata('status', 'finished')
        self.CallCommand(main_path, 'rm -r caver')
        self.CallCommand(main_path + '/analyse', 'python2.7 top_pull.py')
        self.CallCommand(main_path + '/analyse', 'rm top_pull.py')

    def setupOptions(self):
        gromacs_version = self.dataController.getdata('gromacs_version ')
        version_array = gromacs_version.split(' VERSION ')[1].split('.')
        print version_array
        # If version >= 5
        if int(version_array[0]) == 5:
            # If version >= 5.1
            if int(version_array[1]) > 0:
                self.GroLeft = gromacs_version.split(' VERSION ')[0]
                self.GroRight = ''
            else:
                # Check gmx
                mdrun_array = gromacs_version.split(' VERSION ')[0].split(
                    'mdrun')
                self.GroLeft = 'gmx '
                self.GroRight = mdrun_array[1]

            self.GroVersion = 5
        # If version = 4
        else:
            mdrun_array = gromacs_version.split(' VERSION ')[0].split('mdrun')
            self.GroLeft = mdrun_array[0]
            self.GroRight = mdrun_array[1]
            self.GroVersion = 4

        # Set number of core or gpu
        number_cores = self.dataController.getdata('maximum_cores ')
        if int(number_cores) > 0:
            self.GroOption = ' -ntomp ' + number_cores
        else:
            self.GroOption = ''

        check_gpu = check_output(gromacs_version.split(' VERSION ')[0] +
                                 " -version",
                                 shell=True,
                                 executable='/bin/bash').splitlines()
        if ([s for s in check_gpu if "GPU support:" in s
             ][0].split(":")[1].replace(' ', '') == 'enabled'):
            self.GroOption += ' -gpu_id 0'

        #Repeat times
        self.repeat_times = int(self.dataController.getdata('repeat_times '))

    def CallCommand(self, patch, command):
        call('cd ' + patch + '; ' + command,
             shell=True,
             executable='/bin/bash')
Ejemplo n.º 7
0
class SettingScreen(Screen):
    root_path = os.path.dirname(__file__)
    dataController = DataController()

    nvtNsteps = ObjectProperty(None)
    nvtNst = ObjectProperty(None)
    nptNsteps = ObjectProperty(None)
    nptNst = ObjectProperty(None)
    mdNsteps = ObjectProperty(None)
    mdNst = ObjectProperty(None)
    smdNsteps = ObjectProperty(None)
    smdNst = ObjectProperty(None)
    smdVel = ObjectProperty(None)
    smdK = ObjectProperty(None)
    smdDirection = ObjectProperty(None)
    smdDistance = ObjectProperty(None)

    def __init__(self, *args, **kwargs):
        super(SettingScreen, self).__init__(*args, **kwargs)

        self.nvtNsteps.text = self.dataController.getdata('nvt-nsteps ')
        self.nvtNst.text = self.dataController.getdata('nvt-nst ')
        self.nptNsteps.text = self.dataController.getdata('npt-nsteps ')
        self.nptNst.text = self.dataController.getdata('npt-nst ')
        self.mdNsteps.text = self.dataController.getdata('md-nsteps ')
        self.mdNst.text = self.dataController.getdata('md-nst ')
        self.smdNsteps.text = self.dataController.getdata('smd-nsteps ')
        self.smdNst.text = self.dataController.getdata('smd-nst ')
        self.smdVel.text = self.dataController.getdata('smd-vel ')
        self.smdK.text = self.dataController.getdata('smd-k ')

        if (self.dataController.getdata('smd-direction') == 'True'):
            self.smdDirection.active = True
        else:
            self.smdDirection.active = False

        if (self.dataController.getdata('smd-distance') == 'True'):
            self.smdDistance.active = True
        else:
            self.smdDistance.active = False

        self.nvtNsteps.bind(text=self.on_nvt_nsteps)
        self.nvtNst.bind(text=self.on_nvt_nst)
        self.nptNsteps.bind(text=self.on_npt_nsteps)
        self.nptNst.bind(text=self.on_npt_nst)
        self.mdNsteps.bind(text=self.on_md_nsteps)
        self.mdNst.bind(text=self.on_md_nst)
        self.smdNsteps.bind(text=self.on_smd_nsteps)
        self.smdNst.bind(text=self.on_smd_nst)
        self.smdVel.bind(text=self.on_smd_vel)
        self.smdK.bind(text=self.on_smd_k)
        self.smdDirection.bind(active=self.smd_direction)
        self.smdDistance.bind(active=self.smd_distance)
        pass

    def on_nvt_nsteps(self, instance, value):
        self.dataController.setdata('nvt-nsteps ', value)

    def on_nvt_nst(self, instance, value):
        self.dataController.setdata('nvt-nst ', value)

    def on_npt_nsteps(self, instance, value):
        self.dataController.setdata('npt-nsteps ', value)

    def on_npt_nst(self, instance, value):
        self.dataController.setdata('npt-nst ', value)

    def on_md_nsteps(self, instance, value):
        self.dataController.setdata('md-nsteps ', value)

    def on_md_nst(self, instance, value):
        self.dataController.setdata('md-nst ', value)

    def on_smd_nsteps(self, instance, value):
        self.dataController.setdata('smd-nsteps ', value)

    def on_smd_nst(self, instance, value):
        self.dataController.setdata('smd-nst ', value)

    def on_smd_vel(self, instance, value):
        self.dataController.setdata('smd-vel ', value)

    def on_smd_k(self, instance, value):
        self.dataController.setdata('smd-k ', value)

    def smd_direction(self, checkbox, value):
        self.dataController.setdata('smd-direction', str(value))
        #self.dataController.setdata('smd-distance', str(not value))

    def smd_distance(self, checkbox, value):
        self.dataController.setdata('smd-distance', str(value))