Ejemplo n.º 1
0
    def get_shift_from_rst(self, res1_number, atom1_name, res2_number,
                           atom2_name, parm, new_rst):
        from pyxmol.geometry import distance, angle_deg, translate
        from parmed.amber import NetCDFTraj, Rst7, AmberParm
        from parmed.geometry import distance2
        import numpy as np

        for a in parm.atoms:
            if a.residue.number == (res1_number - 1) and a.name == atom1_name:
                A1 = a
            elif a.residue.number == (res2_number -
                                      1) and a.name == atom2_name:
                A2 = a
        best_dist = np.sqrt(distance2(A1, A2))
        #self.log('start get_shift_from_rst')
        #self.log('best_dist: {}'.format(best_dist))
        A, B, C = self.make_current_lattice_vectors(new_rst.box)
        for i in range(-1, 2):
            for j in range(-1, 2):
                for k in range(-1, 2):
                    shift = i * A + j * B + k * C
                    #self.log('shift: {}'.format(shift))
                    A2.xx += shift[0]
                    A2.xy += shift[1]
                    A2.xz += shift[2]
                    dist = np.sqrt(distance2(A1, A2))
                    #self.log('dist: {}, best_dist: {}, (best_dist-dist): {}'.format(round(dist, 9), round(best_dist, 9), best_dist-dist))
                    if round(dist, 9) <= round(best_dist, 9):
                        best_dist = dist
                        best_shift = shift
                        #self.log('best shift: {}'.format(best_shift))
                    A2.xx -= shift[0]
                    A2.xy -= shift[1]
                    A2.xz -= shift[2]
        return best_dist, best_shift
Ejemplo n.º 2
0
    def get_shift_from_nc(self, frame_number, res1_number, atom1_name,
                          res2_number, atom2_name, parm, traj):
        from pyxmol.geometry import distance, angle_deg, translate
        from parmed.amber import NetCDFTraj, Rst7, AmberParm
        from parmed.geometry import distance2
        import numpy as np

        new_rst7 = Rst7(natom=traj.atom)
        new_rst7.coordinates = traj.coordinates[frame_number]
        new_rst7.box = traj.box[frame_number]

        parm.load_rst7(new_rst7)
        for a in parm.atoms:
            if a.residue.number == (res1_number - 1) and a.name == atom1_name:
                A1 = a
            elif a.residue.number == (res2_number -
                                      1) and a.name == atom2_name:
                A2 = a
        best_dist = np.sqrt(distance2(A1, A2))
        A, B, C = self.make_current_lattice_vectors(traj.box[frame_number])
        for i in range(-1, 2):
            for j in range(-1, 2):
                for k in range(-1, 2):
                    shift = i * A + j * B + k * C
                    A2.xx += shift[0]
                    A2.xy += shift[1]
                    A2.xz += shift[2]
                    dist = np.sqrt(distance2(A1, A2))
                    if dist < best_dist:
                        best_dist = dist
                        best_shift = shift
                    A2.xx -= shift[0]
                    A2.xy -= shift[1]
                    A2.xz -= shift[2]
        return best_dist, best_shift
Ejemplo n.º 3
0
 def test_distance2(self):
     """ Tests the distance2 calculation """
     a1, a2 = Atom(), Atom()
     a1.xx = a1.xy = a1.xz = 0
     a2.xx = 3
     a2.xy = 4
     a2.xz = 0
     self.assertEqual(geo.distance2(a1, a2), 25)
     # Make sure it also works for tuples and a mixture of both
     self.assertEqual(geo.distance2((0, 0, 0), (3, 4, 0)), 25)
     self.assertEqual(geo.distance2(a1, (3, 4, 0)), 25)
     self.assertEqual(geo.distance2((0, 0, 0), a2), 25)
Ejemplo n.º 4
0
 def test_distance2(self):
     """ Tests the distance2 calculation """
     a1, a2 = Atom(), Atom()
     a1.xx = a1.xy = a1.xz = 0
     a2.xx = 3
     a2.xy = 4
     a2.xz = 0
     self.assertEqual(geo.distance2(a1, a2), 25)
     # Make sure it also works for tuples and a mixture of both
     self.assertEqual(geo.distance2((0, 0, 0), (3, 4, 0)), 25)
     self.assertEqual(geo.distance2(a1, (3, 4, 0)), 25)
     self.assertEqual(geo.distance2((0, 0, 0), a2), 25)
Ejemplo n.º 5
0
def getAtomSerialFromAmberMaskHbond(combined_pmd,resnumber,atomname,distance,ligresname="LIG"):
    lig_sel=parmed.amber.mask.AmberMask(combined_pmd,"(((:"+resnumber+")&(@"+atomname+"))<@"+distance+") & (:"+ligresname+" & (@N=|@O=))")
    lig_idx=[x for x in lig_sel.Selected() ]
    rec_sel=parmed.amber.mask.AmberMask(combined_pmd,"((:"+resnumber+")&(@"+atomname+"))")
    rec_idx=[x for x in rec_sel.Selected() ]


    print(lig_idx,rec_idx)
    
    if len(rec_idx)==1 :

        if(len(lig_idx)>1) :
            mind=1000
            minidx=lig_idx[0]
            for idx in lig_idx:
                d=g.distance2(combined_pmd[idx],combined_pmd[rec_idx[0]])
                if d<mind:
                    mind=d
                    minidx=idx
            return(rec_idx[0],minidx) 
        else :
            return(rec_idx[0],lig_idx[0])        
        #sys.exit("The reaction coordinate selection failed here, please consider setting it by hand")
    else :
        sys.exit("Your receptor atom selection selected more than a single atom. PLease check your atom names or refine your selection")
Ejemplo n.º 6
0
def find_result(res_atom=None, prot_file=None, combined_pmd=None):
    # Find the
    distance_atom_1, prot_atom = find_atom(res_atom, prot_file, combined_pmd)
    # Now find the one nearest
    distance_atom_2 = [(x.idx, distance2(x, prot_atom))
                       for x in combined_pmd.atoms if is_lig(x)]
    distance_atom_2.sort(key=operator.itemgetter(1))
    # These are the interactions to find
    index_one = distance_atom_1[0][0]
    index_two = distance_atom_2[0][0]
    out_res = [index_one, index_two, math.sqrt(distance_atom_2[0][1])]
    return index_one, index_two, out_res, distance_atom_2[0][1]
Ejemplo n.º 7
0
Archivo: chunk.py Proyecto: xchem/duck
def find_disulfides(input_file, threshold=6.2):
    structure = parmed.load_file(input_file)
    sulfurs = [x for x in structure.atoms if x.residue.name == "CYS" and x.name == "SG"]
    disulfides = []
    for atom_one in sulfurs:
        for atom_two in sulfurs:
            if atom_one.idx >= atom_two.idx:
                continue
            dist = distance2(atom_one, atom_two)
            if dist < threshold:
                atom_one.residue.name = "CYX"
                atom_two.residue.name = "CYX"
                disulfides.append((atom_one.residue.number, atom_two.residue.number))
    structure.write_pdb(input_file)
    return disulfides
Ejemplo n.º 8
0
    def get_dist_and_angle(self, res1_number, atom1_name, res2_number,
                           atom2_name, res3_number, atom3_name, parm):
        from parmed.amber import AmberParm, Rst7
        from parmed.geometry import distance2
        import numpy as np

        rst = Rst7(MD._run_dir + "/run" + MD._pattern % self.current_step +
                   "mod.rst")
        parm.load_rst7(rst)
        for a in parm.atoms:
            if a.residue.number == (res1_number - 1) and a.name == atom1_name:
                A1 = a
            elif a.residue.number == (res2_number -
                                      1) and a.name == atom2_name:
                A2 = a
            elif a.residue.number == (res3_number -
                                      1) and a.name == atom3_name:
                A3 = a
        A1_A2 = distance2(A1, A2)
        A1_A3 = distance2(A1, A3)
        A2_A3 = distance2(A2, A3)
        cos = (A1_A2 + A2_A3 - A1_A3) / (2 * np.sqrt(A1_A2) * np.sqrt(A2_A3))
        A1_A2_A3 = np.degrees(np.arccos(cos))
        return np.sqrt(A1_A2), A1_A2_A3
Ejemplo n.º 9
0
def find_atom(res_atom=None, prot_file=None, combined_pmd=None):
    # Parse the input data like this -> "A_LYS_311_N"
    chain = res_atom.split("_")[0]
    res_name = res_atom.split("_")[1]
    res_number = int(res_atom.split("_")[2])
    atom_name = res_atom.split("_")[3]
    # Read the original PDB File and find the atom coords
    protein = parmed.load_file(prot_file)
    for atom in protein.atoms:
        if check_same(atom, chain, res_name, res_number, atom_name):
            prot_atom = atom
            break
    distance_atom_1 = [(x.idx, distance2(x, prot_atom))
                       for x in combined_pmd.atoms]
    distance_atom_1.sort(key=operator.itemgetter(1))
    return distance_atom_1, prot_atom
Ejemplo n.º 10
0
def find_lig_id(pdb_file, het_pdb, res_name, res_num, atom_name):
    print(pdb_file)
    protein = parmed.load_file(pdb_file)
    atoms = []
    for residue in protein.residues:
        if residue.name == res_name:
            if residue.number == res_num:
                for atom in residue.atoms:
                    if atom.name == atom_name:
                        atoms.append(atom)
    if len(atoms)==0:
        print("ISSUE FINDING ATOM: "+" ".join([pdb_file,res_name, str(res_num), atom_name]))
        sys.exit()
    else:
        prot_atom = atoms[0]
    ligands = parmed.load_file(het_pdb)["!(:HOH,NA,CL)"]
    distance_atom_2 = [(x.residue.name, math.sqrt(distance2(x, prot_atom)),x.name) for x in ligands.atoms]
    distance_atom_2.sort(key=operator.itemgetter(1))
    print(distance_atom_2[0],distance_atom_2[1],distance_atom_2[2])
    return distance_atom_2[0][0]