def detect_aromatic_rings_in_protein(self):
        """Use rdkit to detect aromatic rings in protein. A (relatively) simpler case, since only 4 of 20 aa have rings.
        Since different forcefields can have different atom names, each of 4 aromatic residues is extracted as PDB file
        and the aromatic rings are detected for each. The case is trickier with TRP, since this residue has two aromatic rings -
        these are considered separately.
        Data is saved in self.rings dictionary."""
        self.rings = {}
        for ar_resname in ["PHE","TRP","TYR","HIS"]:
            for res in self.topology_data.universe.residues:
                if res.resname == ar_resname:
                    aromatic_aa = self.topology_data.universe.select_atoms("resname "+res.resname+" and resid "+str(res.resid)+" and segid "+ res.segid)
                    aromatic_aa.write(ar_resname+".pdb")
                    break
        for ar_resname in ["PHE","TRP","TYR","HIS"]:
            try:
                arom_aa_rdkit = Chem.MolFromPDBFile(ar_resname+".pdb")
                arom_aa_mda = MDAnalysis.Universe(ar_resname+".pdb")
                ring_info = arom_aa_rdkit.GetRingInfo()
                number_of_rings = ring_info.NumRings()
                for ring in range(number_of_rings):
                    atom_names_in_ring = []
                    for atom in ring_info.AtomRings()[ring]:
                        atom_names_in_ring.append(arom_aa_mda.atoms[atom].name)
                    self.rings[(ar_resname,ring)]=atom_names_in_ring
            except IOError:
                continue
def detect_aromatic_rings_in_protein ( self ) : self . rings = { } for ar_resname in [ "PHE" , "TRP" , "TYR" , "HIS" ] : for res in self . topology_data . universe . residues : if res . resname == ar_resname : aromatic_aa = self . topology_data . universe . select_atoms ( "resname " + res . resname + " and resid " + str ( res . resid ) + " and segid " + res . segid ) aromatic_aa . write ( ar_resname + ".pdb" ) break for ar_resname in [ "PHE" , "TRP" , "TYR" , "HIS" ] : try : arom_aa_rdkit = Chem . MolFromPDBFile ( ar_resname + ".pdb" ) arom_aa_mda = MDAnalysis . Universe ( ar_resname + ".pdb" ) ring_info = arom_aa_rdkit . GetRingInfo ( ) number_of_rings = ring_info . NumRings ( ) for ring in range ( number_of_rings ) : atom_names_in_ring = [ ] for atom in ring_info . AtomRings ( ) [ ring ] : atom_names_in_ring . append ( arom_aa_mda . atoms [ atom ] . name ) self . rings [ ( ar_resname , ring ) ] = atom_names_in_ring except IOError : continue
Use rdkit to detect aromatic rings in protein. A (relatively) simpler case, since only 4 of 20 aa have rings.
        Since different forcefields can have different atom names, each of 4 aromatic residues is extracted as PDB file
        and the aromatic rings are detected for each. The case is trickier with TRP, since this residue has two aromatic rings -
        these are considered separately.
        Data is saved in self.rings dictionary.