コード例 #1
0
ファイル: QresFEP.py プロジェクト: Katherinvalleos/qligfep
 def checkFEP(self):
     if len(self.mutation[0]) == 1:
         AA_from = IO.AA(self.mutation[0])
         
     else:
         AA_from = self.mutation[0]
         
     AA_to = IO.AA(self.mutation[2])
     mutation = '{}{}{}'.format(*self.mutation)
     FEPdir = s.FF_DIR + '/.FEP/' + self.forcefield +  '/' + AA_from + '_' + AA_to
         
     if not os.path.exists(FEPdir):
         if self.dual == True:
             'Generating dual topology inputfiles'
             self.FEPlist = ['FEP1.fep']
             self.FEPdir = None
             
         else:    
             print('FATAL: no FEP files found for the {} mutation' \
                   'in {} exiting now.'.format(mutation,
                                               FEPdir))
             sys.exit()
     
     else:
         for line in sorted(glob.glob(FEPdir + '/FEP*.fep')):
             line = line.split('/')
             self.FEPlist.append(line[-1])
         self.FEPdir = FEPdir
コード例 #2
0
ファイル: resFEP.py プロジェクト: xy21hb/setupFEP
    def checkFEP(self):
        if len(self.mutation[0]) == 1:
            AA_from = IO.AA(self.mutation[0])

        else:
            AA_from = self.mutation[0]

        AA_to = IO.AA(self.mutation[2])
        mutation = '{}{}{}'.format(*self.mutation)
        FEPdir = s.FF_DIR + '/.FEP/' + AA_from + '_' + AA_to
        if self.forcefield == 'OPLS2005':
            FEPdir = FEPdir + '-aa'

        if not os.path.exists(FEPdir):
            print 'FATAL: no FEP files found for the {} mutation' \
                  'in {} exiting now.'.format(mutation,
                                              FEPdir)
            sys.exit()

        else:
            for line in sorted(glob.glob(FEPdir + '/FEP*.fep')):
                line = line.split('/')
                self.FEPlist.append(line[-1])
            self.FEPdir = FEPdir
コード例 #3
0
 def General(self):
     for atom in self.top:
         if len(atom[0]) != 6:
             continue
         try:
             IO.AA(atom[4])
             self.protein.append(atom[1])
         except:
             if atom[4] == 'LIG':
                 self.ligand.append(atom[1])
             else:
                 continue
     self.commands = [self.eq_top, '1', str(self.protein[0])+' '+str(self.protein[-1]),
                      str(self.ligand[0])+' '+str(self.ligand[-1]), 'end', 'go', self.MD, '.']
     with open(self.inp, 'w') as outfile:
         for line in self.commands:
             outfile.write(line+'\n')
コード例 #4
0
    def create_dual_lib(self):
        FFlib = {}
        self.merged_lib = {}
        replacements = {}

        if self.dual == False:
            return None

        headers = [
            '[atoms]', '[bonds]', '[connections]', '[impropers]', '[info]'
        ]
        if self.forcefield[0:4] == 'OPLS':
            headers.append('[charge_groups]')

        libfiles = [s.FF_DIR + '/' + self.forcefield + '.lib']
        if self.nonAA == True:
            libfiles.append(self.mutation[2] + '.lib')
        for libfile in libfiles:
            with open(libfile) as infile:
                for line in infile:
                    if line[0] == '*':
                        continue

                    if line[0] == '{':
                        RESname = line.split('}')[0][1:]
                        continue

                    try:
                        FFlib[RESname].append(line)

                    except:
                        FFlib[RESname] = [line]

        # Read the WT residue
        if len(self.mutation[0]) == 1:
            AA = AA(self.mutation[0])
        else:
            AA = self.mutation[0]
        for line in FFlib[AA]:
            if line.strip() in headers:
                header = line.strip()
                self.merged_lib[header] = []

            else:
                self.merged_lib[header].append(line)

        # Add CA CBx bond
        self.merged_lib['[bonds]'].append('       CA     cb\n')

        ## Read the mutant residue
        # Construct atom name replacements
        if len(self.mutation[2]) == 1:
            AA = IO.AA(self.mutation[2])

        else:
            AA = self.mutation[2]
        for line in FFlib[AA]:
            line = line.strip()
            line = line.split()
            if line != headers[0]:
                if len(line) > 2:
                    atom = line[1]
                    if atom != 'H':
                        replacements[atom] = atom.lower()

                if line == header[1]:
                    break

        for line in FFlib[AA]:
            if line.strip() in headers:
                header = line.strip()

            if line[0] == '!':
                continue
            if len(line.split()) < 2:
                continue

            else:
                # connection flag only needs to be there once
                if header == headers[2]:
                    continue

                # Remove overlapping backbone definitions
                if line.split()[0] == 'O' \
                or line.split()[0] == 'C' \
                or line.split()[0] == 'CA'     \
                or line.split()[0] == 'N'   \
                or line.split()[0] == 'H'     \
                or line.split()[0] == 'HA':
                    continue

                if line.split()[1] == 'O' \
                or line.split()[1] == 'C' \
                or line.split()[1] == 'CA'     \
                or line.split()[1] == 'N'   \
                or line.split()[1] == 'H'     \
                or line.split()[1] == 'HA':
                    continue

                # Merge the library on the reference
                line = IO.replace(line, replacements)
                self.merged_lib[header].append(line)

        # Write out the merged library file
        out = self.directory + '/inputfiles/' + self.MUTresn + '.lib'
        with open(out, 'w') as outfile:
            self.merged_lib['[charge_groups]'] = []
            cnt = 0
            outfile.write('{' + self.MUTresn + '}\n\n')
            for header in headers:
                outfile.write('\n    ' + header + '\n')
                if not header in self.merged_lib:
                    continue
                for line in self.merged_lib[header]:
                    if header == '[atoms]':
                        cnt += 1
                        line = line.split()
                        outfile.write('    {:2d} {:<10}{:<10}{:<10}\n'.format(
                            cnt, line[1], line[2], line[3]))
                    else:
                        outfile.write(line)
コード例 #5
0
    def readpdb(self):
        atnr = 0
        if len(self.mutation[2]) == 1:
            if self.nonAA != True:
                self.MUTresn = '{}2{}'.format(self.mutation[0],
                                              self.mutation[2])
            else:
                self.MUTresn = '{}2{}'.format(self.mutation[0], 'X')

        elif len(self.mutation[2]) == 3:
            self.MUTresn = '{}2{}'.format(IO.AA(self.mutation[0]),
                                          IO.AA(self.mutation[2]))
        #self.backbone = []
        self.backbone = ['C', 'O', 'CA', 'N', 'H', 'HA']
        # Read in the mutant residue
        if self.dual == True:
            MUT = []
            with open(self.mutation[2] + '.pdb') as infile:
                for line in infile:
                    line = IO.pdb_parse_in(line)
                    # The residue name should match the mutant residue number
                    # relative to Q numbering from protPREP.log
                    line[6] = int(self.PDB2Q[self.mutation[1]])
                    if line[2] in self.backbone:
                        continue

                    else:
                        MUT.append(line)

        pdb_files = ['protein.pdb']
        if self.cofactor[0] != None:
            for line in self.cofactor:
                pdb_files.append(line + '.pdb')

        for pdb_file in pdb_files:
            with open(pdb_file) as infile:
                for line in infile:
                    if line.startswith(self.include):
                        atnr += 1
                        line = IO.pdb_parse_in(line)
                        if pdb_file != 'protein.pdb':
                            line[6] = resoffset + 1
                            line[1] = self.systemsize

                        line[1] = atnr

                        # Change to hybrid residue name
                        if self.dual == True:
                            if str(line[6]) == self.PDB2Q[self.mutation[1]]:
                                line[4] = self.MUTresn

                        # Generate the dual topology residue in the PDB dictionary
                        # Construct the PDB dictionary
                        try:
                            self.PDB[line[6]].append(line)

                        except:
                            self.PDB[line[6]] = [line]

                        if self.dual == True:
                            if str(line[6]) == self.PDB2Q[self.mutation[1]]:
                                if line[2] == 'O':
                                    for MUTat in MUT:
                                        atnr += 1
                                        if MUTat[2] not in self.backbone:
                                            # Atom name cannot be longer than 4 characters
                                            #if len(MUTat[2]) <= 3:
                                            #    MUTat[2] = MUTat[2] + 'x'

                                            #elif len(MUTat[2]) == 4:
                                            #    MUTat[2] = MUTat[2][0:1] + 'x'
                                            MUTat[2] = MUTat[2].lower()

                                            MUTat[1] = atnr
                                            MUTat[4] = self.MUTresn

                                            try:
                                                self.PDB[MUTat[6]].append(
                                                    MUTat)

                                            except:
                                                self.PDB[MUTat[6]] = [MUTat]

                                            self.dualMUT['0'].append(MUTat)

                                self.dualMUT['1'].append(line)

                        self.systemsize += 1

                resoffset = len(self.PDB)