Ejemplo n.º 1
0
def main():
    args = parse_arguments()

    file_list = []
    for item in args.infile:
        if '*' in item:
            file_list += list(glob.glob(item))
        else:
            file_list.append(item)

    if args.snapshots:
        snapshot_indices = read_snapshot_indices(args.snapshots)
        assert len(file_list) == 1, ("Should only run 1 file at a time with "
                                     "particular snapshots specified!")
    else:
        snapshot_indices = None

    for mae_file in file_list:
        s = load_structure_reader(mae_file)

        lig_out = '%d_lig.maegz'
        rcp_out = '%d_rcp.maegz'
        if args.lig_fmt:
            assert re.search(r'.*%d.*\.maegz', args.lig_fmt)
            lig_out = args.lig_fmt
        if args.rcp_fmt:
            assert re.search(r'.*%d.*\.maegz', args.rcp_fmt)
            rcp_out = args.rcp_fmt

        rcp_asl = args.rcp_asl
        lig_asl = args.lig_asl

        j = 1
        for i, lig_st in enumerate(s):
            if snapshot_indices and i not in snapshot_indices:
                continue

            rcp_st = lig_st.copy()

            lig_trj = lig_out % j
            rcp_trj = rcp_out % j

            # Select and delete lig from rcp structure
            lig_selection = structureutil.evaluate_asl(rcp_st, lig_asl)
            rcp_st.deleteAtoms(lig_selection)
            rcp_st.append(rcp_trj)

            # Select and delete rcp from lig structure
            rcp_selection = structureutil.evaluate_asl(lig_st, rcp_asl)
            lig_st.deleteAtoms(rcp_selection)
            lig_st.append(lig_trj)

            j += 1
Ejemplo n.º 2
0
    def writeRecStructureFile(self): 
        receptor_file =  self.keywords.get('RECEPTOR_FILE')
        if not receptor_file:
            msg = "bedam_prep: No receptor file specified in the input file"
            self.exit(msg)
        if not os.path.exists(receptor_file):
            msg = 'File does not exist: %s' % receptor_file
            self.exit(msg)
        receptor_asl =  self.keywords.get('REST_RECEPTOR_ASL')

        try:
            st = structure.StructureReader(receptor_file).next()
        except:
            print "Cannot open Maestro structure file %s" % receptor_file
            sys.exit(-1)

        atoms = []
        if receptor_asl:
            atoms = structureutil.evaluate_asl(st, receptor_asl)
        
        # all atoms free
        for atom in st.atom:
            atom.property['i_i_constraint'] = 0
        # buffer the ones in ASL
        for iat in atoms:
            st.atom[iat].property['i_i_constraint'] = 2

        receptor_file_restr =   self.jobname + '_rcpt_restr' + '.maegz'
        st.write(receptor_file_restr)
        self.receptor_file_restr = receptor_file_restr
        self.ligand_file_restr = self.ligidxfile
Ejemplo n.º 3
0
    def __init__(self,  receptor):
        
        self.POLAR_RESIDUES = ["ARG","ASP","GLU","HIS","ASN","GLN","LYS","SER","THR","ARN","ASH","GLH","HID","HIE","LYN"]
        self.HYDROPHOBIC_RESIDUES =["PHE","LEU","ILE","TYR","TRP","VAL","MET","PRO","CYS","ALA","CYX"]
        self.AROMATIC_RESIDUES = ["PHE","TYR","TRP","TYO"]
        self.CHARGED_RESIDUES = ["ARG","ASP","GLU","LYS","HIP","CYT","SRO","TYO","THO"]

        # Bit positions for each interaction:
        self.bit_pos = {'CONTACT' : 0,  'BACKBONE' : 1,  'SIDECHAIN' : 2,  'POLAR' : 3,  'HYDROPHOBIC' : 4,  'H_ACCEPTOR' : 5,  'H_DONOR' : 6,  'AROMATIC' : 7,  'CHARGED' : 8}
        self.active_bits = ['CONTACT',  'BACKBONE',  'SIDECHAIN',  'POLAR', 'HYDROPHOBIC',  'H_ACCEPTOR',  'H_DONOR',  'AROMATIC',  'CHARGED']
        self.max_bits_per_residue =  9 
        self.used_bits_number = len(self.active_bits)
        
        self.sifts = {}

        self.receptor_st = receptor

        backbone_list = structureutil.evaluate_asl( self.receptor_st,
                                                    "backbone")
        self.backbone_set = set(backbone_list)

        """
        structureutil.evaluate_asl
        
        Search for substructures matching the ASL (Atom Specification Language)

        the atom index is returned
        """
        
        polar_list = structureutil.evaluate_asl( self.receptor_st,
                                                    "res. " + ', '.join(self.POLAR_RESIDUES ))
        self.polar_set = set( polar_list )
        hydrophobic_list = structureutil.evaluate_asl( self.receptor_st,
                                                    "res. " + ', '.join(self.HYDROPHOBIC_RESIDUES))
        self.hydrophobic_set = set( hydrophobic_list )
        aromatic_list = structureutil.evaluate_asl( self.receptor_st,
                                                    "res. " + ', '.join(self.AROMATIC_RESIDUES))
        self.aromatic_set = set(aromatic_list)
        charged_list = structureutil.evaluate_asl ( self.receptor_st,
                                                    "res. " + ', '.join(self.CHARGED_RESIDUES))
        self.charged_set = set( charged_list )
Ejemplo n.º 4
0
    def find_close_residues(self, ligand, cutoff=4.0):
        lig_name = ligand.title
        d_ = defaultdict(list)
        for atom in ligand.atom:
            # the distance to original point?
            lig_dist = self.measure_dist([atom.xyz])

            # range should refer to the node level in the red black tree
            close_atoms = self.distances.find_nodes_in_range(lig_dist - cutoff, lig_dist + cutoff)

            for close in close_atoms:
                atom_atom_dist = self.measure_dist([atom.xyz], close.data.coords)
                if atom_atom_dist <= cutoff:
                    self.update_min_max(close.data.res_num)
                    d_[close.data.atom].append((ligand.title, atom))

                    # Just take into account the special case, H_DONOR and H_RECEPTOR
                    self.fingerprints.add_sift_chunk_special_case(close.data.atom, atom, ligand.title, atom_atom_dist)

        max_atom_nums = max([len(atom_list) for atom_list in d_.values()])
        # modified definition of interaction
        # print "max in-range atoms count ",max_atom_nums
        strong_c = 0
        exists_c = 0
        for close_atom, lig_names in d_.items():
            # print lig_names
            if len(lig_names) >= 3:
                # print "mark as strong"
                self.fingerprints.add_sift_chunk_ordinary(
                    close_atom, lig_names[0][0], "strong"
                )  # we have only on ligand per complex
                strong_c += 1
            else:
                # print "mark as exists"
                self.fingerprints.add_sift_chunk_ordinary(close_atom, lig_names[0][0], "exists")
                exists_c += 1
        print sorted([len(lig_names) for lig_names in d_.values()])

        ####### start of environmental descriptors ########
        # print "strong count",strong_c ,"exists count",exists_c
        # addition of surrounding environment
        POLAR_RESIDUES = [
            "ARG",
            "ASP",
            "GLU",
            "HIS",
            "ASN",
            "GLN",
            "LYS",
            "SER",
            "THR",
            "ARN",
            "ASH",
            "GLH",
            "HID",
            "HIE",
            "LYN",
        ]
        HYDROPHOBIC_RESIDUES = ["PHE", "LEU", "ILE", "TYR", "TRP", "VAL", "MET", "PRO", "CYS", "ALA", "CYX"]
        AROMATIC_RESIDUES = ["PHE", "TYR", "TRP", "TYO"]
        CHARGED_RESIDUES = ["ARG", "ASP", "GLU", "LYS", "HIP", "CYT", "SRO", "TYO", "THO"]

        polar_list = structureutil.evaluate_asl(ligand, "res. " + ", ".join(POLAR_RESIDUES))
        polar_set = set(polar_list)
        hydrophobic_list = structureutil.evaluate_asl(ligand, "res. " + ", ".join(HYDROPHOBIC_RESIDUES))
        hydrophobic_set = set(hydrophobic_list)
        aromatic_list = structureutil.evaluate_asl(ligand, "res. " + ", ".join(AROMATIC_RESIDUES))
        aromatic_set = set(aromatic_list)
        charged_list = structureutil.evaluate_asl(ligand, "res. " + ", ".join(CHARGED_RESIDUES))
        charged_set = set(charged_list)

        # print polar_set, hydrophobic_set ,aromatic_set , charged_set
        env_d_ = dict()
        for close_atom, lig_names in d_.items():
            for lig_atom in [l[1] for l in lig_names]:
                lig_atom = int(lig_atom)
                if close_atom not in env_d_.keys():
                    env_d_[close_atom] = defaultdict(int)
                if lig_atom in polar_set:
                    # print "it is polar"
                    env_d_[close_atom]["ENV_POLAR"] += 1
                elif lig_atom in aromatic_set:
                    # print "it is aromatic"
                    env_d_[close_atom]["ENV_AROMATIC"] += 1
                elif lig_atom in hydrophobic_set:
                    # print "it is h"
                    env_d_[close_atom]["ENV_HYDROPHOBIC"] += 1
                elif lig_atom in charged_set:
                    # print "it is c"
                    env_d_[close_atom]["ENV_CHARGED"] += 1

        atom_nums = list()
        for a, fp in env_d_.items():
            atom_nums += fp.values()
        max_atom_nums = max(atom_nums)
        env_stat = {"p_list": [0], "a_list": [0], "h_list": [0], "c_list": [0]}
        env_stat["p_list"] += [fp["ENV_POLAR"] for a, fp in env_d_.items() if fp["ENV_POLAR"] != 0]
        env_stat["a_list"] += [fp["ENV_AROMATIC"] for a, fp in env_d_.items() if fp["ENV_AROMATIC"] != 0]
        env_stat["h_list"] += [fp["ENV_HYDROPHOBIC"] for a, fp in env_d_.items() if fp["ENV_HYDROPHOBIC"] != 0]
        env_stat["c_list"] += [fp["ENV_CHARGED"] for a, fp in env_d_.items() if fp["ENV_CHARGED"] != 0]
        print env_stat
        print max(env_stat["p_list"]), max(env_stat["a_list"]), max(env_stat["h_list"]), max(env_stat["c_list"])
        strong_c = 0
        exists_c = 0
        for a, fp in env_d_.items():
            for t, c in fp.items():
                if c >= 3:
                    self.fingerprints.add_sift_chunk_env(a, lig_name, t, "strong")
                    strong_c += 1
                else:
                    self.fingerprints.add_sift_chunk_env(a, lig_name, t, "exists")
                    exists_c += 1
Ejemplo n.º 5
0
    def __init__(self, receptor):

        self.POLAR_RESIDUES = [
            "ARG",
            "ASP",
            "GLU",
            "HIS",
            "ASN",
            "GLN",
            "LYS",
            "SER",
            "THR",
            "ARN",
            "ASH",
            "GLH",
            "HID",
            "HIE",
            "LYN",
        ]
        self.HYDROPHOBIC_RESIDUES = ["PHE", "LEU", "ILE", "TYR", "TRP", "VAL", "MET", "PRO", "CYS", "ALA", "CYX"]
        self.AROMATIC_RESIDUES = ["PHE", "TYR", "TRP", "TYO"]
        self.CHARGED_RESIDUES = ["ARG", "ASP", "GLU", "LYS", "HIP", "CYT", "SRO", "TYO", "THO"]

        # Bit positions for each interaction:
        self.bit_pos = {
            "CONTACT": 0,
            "BACKBONE": 1,
            "SIDECHAIN": 2,
            "POLAR": 3,
            "HYDROPHOBIC": 4,
            "H_ACCEPTOR": 5,
            "H_DONOR": 6,
            "AROMATIC": 7,
            "CHARGED": 8,
            "ENV_POLAR": 9,
            "ENV_HYDROPHOBIC": 10,
            "ENV_AROMATIC": 11,
            "ENV_CHARGED": 12,
        }

        self.active_bits = [
            "CONTACT",
            "BACKBONE",
            "SIDECHAIN",
            "POLAR",
            "HYDROPHOBIC",
            "H_ACCEPTOR",
            "H_DONOR",
            "AROMATIC",
            "CHARGED",
            "ENV_POLAR",
            "ENV_HYDROPHOBIC",
            "ENV_AROMATIC",
            "ENV_CHARGED",
        ]
        self.max_bits_per_residue = 13
        self.used_bits_number = len(self.active_bits)

        self.sifts = {}

        self.receptor_st = receptor

        backbone_list = structureutil.evaluate_asl(self.receptor_st, "backbone")
        self.backbone_set = set(backbone_list)

        """
        structureutil.evaluate_asl
        
        Search for substructures matching the ASL (Atom Specification Language)

        the atom index is returned
        """

        polar_list = structureutil.evaluate_asl(self.receptor_st, "res. " + ", ".join(self.POLAR_RESIDUES))
        self.polar_set = set(polar_list)
        hydrophobic_list = structureutil.evaluate_asl(self.receptor_st, "res. " + ", ".join(self.HYDROPHOBIC_RESIDUES))
        self.hydrophobic_set = set(hydrophobic_list)
        aromatic_list = structureutil.evaluate_asl(self.receptor_st, "res. " + ", ".join(self.AROMATIC_RESIDUES))
        self.aromatic_set = set(aromatic_list)
        charged_list = structureutil.evaluate_asl(self.receptor_st, "res. " + ", ".join(self.CHARGED_RESIDUES))
        self.charged_set = set(charged_list)
Ejemplo n.º 6
0
    def writeRestraintFile(self):
        # check that structure files with internal indexes have been generated
        if self.recidxfile is None or self.ligidxfile is None:
            msg = "writeRestraintFile: Internal error: structure files not found"
            self.exit(msg)
             
        receptor_asl =  self.keywords.get('REST_LIGAND_CMRECASL')
        if not receptor_asl:
            msg = "bedam_prep: No ASL specified for receptor site center"
            self.exit(msg)
        ligand_asl =  self.keywords.get('REST_LIGAND_CMLIGASL')
        if not ligand_asl:
            ligand_asl = '( all)'

        try:
            st = structure.StructureReader(self.recidxfile).next()
        except:
            print "Cannot open Maestro structure file %s" % self.recidxfile
            sys.exit(-1)
        nrecatoms = len(st.atom)
        atoms = structureutil.evaluate_asl(st, receptor_asl)
        rec_atoms = [];
        for iat in atoms:
            rec_atoms.append(st.atom[iat].property['i_i_internal_atom_index'])

        #computes receptor CM
        cmrx = cmry = cmrz = 0.
        for iat in atoms:
            cmrx += st.atom[iat].x
            cmry += st.atom[iat].y
            cmrz += st.atom[iat].z
        n = len(atoms)
        cmrx /= float(n)
        cmry /= float(n)
        cmrz /= float(n)

        try:
            st = structure.StructureReader(self.ligidxfile).next()
        except:
            print "Cannot open Maestro structure file %s" % self.ligidxfile
            sys.exit(-1)
        nligatoms = len(st.atom)
        atoms = structureutil.evaluate_asl(st, ligand_asl)
        lig_atoms = [];
        for iat in atoms:
            lig_atoms.append(st.atom[iat].property['i_i_internal_atom_index']-nrecatoms)

        #computes ligand CM
        cmlx = cmly = cmlz = 0.
        for iat in atoms:
            cmlx += st.atom[iat].x
            cmly += st.atom[iat].y
            cmlz += st.atom[iat].z
        n = len(atoms)
        cmlx /= float(n)
        cmly /= float(n)
        cmlz /= float(n)

        #computes and reports the distance btw CM's
        d = sqrt((cmlx - cmrx)*(cmlx - cmrx) + (cmly - cmry)*(cmly - cmry) + (cmlz - cmrz)*(cmlz - cmrz))
        print "CM-CM distance = %f" % d

        self.restraint_file = self.jobname + '_cmrestraint.dat'
        f = open(self.restraint_file,"w")
        f.write("Receptor\n")
        f.write("%d\n" % 1)
        f.write("%d\n" % len(rec_atoms) )
        for i in rec_atoms:
            f.write("%d\n" % i)
        f.write("Ligand\n")
        f.write("%d\n" % 2)
        f.write("%d\n" % len(lig_atoms) )
        for i in lig_atoms:
            f.write("%d\n" % i)
        f.close()