def get_structure(filename): with open(filename, 'rb') as raw: structure = Cif(raw).structure() """All RNA bases are placed in the standard orientation. All Hydrogen atoms are inferred. Rotation matrix is calculated for each base.""" structure.infer_hydrogens() return structure
def main(filename): with open(filename, 'rb') as raw: structure = Cif(raw).structure() print('Iterating over atoms') for residue in structure.residues(chain='A', sequence='C'): for atom in residue.atoms(): print residue.unit_id() print(atom.name)
def main(filename): with open(filename, 'rb') as raw: structure = Cif(raw).structure() print('Iterating over atoms') for residue in structure.residues(chain='A', sequence = 'U'): for atom in residue.atoms(): print residue print(atom.name)
def main(filename): with open(filename, 'rb') as raw: structure = Cif(raw).structure() print(structure) print(structure.pdb) # print(structure._assemblies) print('Iterating over all units') # print(structure._residues) for residue in structure._residues: if 'base' in residue.centers: print('residue: %s %s' % (residue, residue.centers['base'])) structure.infer_hydrogens() # iterate through all residues ... # when you a = input() print(structure.experimental_sequence('A')) # print(structure.residues) print('Iterating over all parts') for model in structure.models: print('model: %s' % model.model) for chain in model.chains: print(' chain: %s' % chain.chain) for residue in chain.residues(): print(' residue: %s' % residue.unit_id()) # You can use residues to iterate over the residues of a structure # directly. print('Short cut iteration') for residue in structure.residues(): print(residue.unit_id()) # The residues method accepts keyword arguments. These arguments are things # to filter the residues by. Below limits the residues to only those that # have sequence equal to 'A'. print('Iterating over specific residues') for residue in structure.residues(sequence='A'): print(residue.unit_id()) # You can give more than one condition. Below limits the residues to only # those in chain B which are a G or C. print('Iterating over atoms') for residue in structure.residues(chain='B', sequence=['G', 'C']): for atom in residue.atoms(): print(atom.unit_id()) # You can also filter the atoms in the same way. print('Iterating over specific atoms') for residue in structure.residues(chain='A', sequence=['G', 'C']): for atom in residue.atoms(name=['N1', 'C2']): print(atom.unit_id())
def cif(self, pdb): """A method to load the cif file for a given pdb id. If given a CIF file this will return the given CIF file. Parameters ---------- pdb : str or fr3d.cif.reader.CIF PDB id to parse or the file to return. Returns ------- cif : fr3d.cif.reader.Cif The parsed mmCIF file. """ if isinstance(pdb, Cif): return pdb try: with open(self._cif(pdb), 'rb') as raw: return Cif(raw) except ComplexOperatorException as err: if self.skip_complex: self.logger.warning("Got a complex operator for %s, skipping", pdb) raise Skip("Complex operator must be skipped") raise err
def setUpClass(cls): if cls.filename: with open(cls.filename, 'rb') as raw: cls.cif = Cif(raw) cls.structure = cls.cif.structure() else: cls.cif = None cls.structure = None
def deserialize(handle): """Load a serialized cif file. :handle: The filehandle to read from. :returns: A new Cif object from the persisted data. """ data = pickle.load(handle) return Cif(data=data)
def main(filename): with open(filename, 'rb') as raw: structure = Cif(raw).structure() print('Iterating over all parts') for model in structure.models: print('model: %s' % model.model) for chain in model.chains: print(' chain: %s' % chain.chain) for residue in chain.residues(): print(' residue: %s' % residue.unit_id()) # You can use residues to iterate over the residues of a structure # directly. print('Short cut iteration') for residue in structure.residues(): print(residue.unit_id()) # The residues method accepts keyword arguments. These arguments are things # to filter the residues by. Below limits the residues to only those that # have sequence equal to 'A'. print('Iterating over specific residues') for residue in structure.residues(sequence='A'): print(residue.unit_id()) # You can give more than one condition. Below limits the residues to only # those in chain B which are a G or C. print('Iterating over atoms') for residue in structure.residues(chain='B', sequence=['G', 'C']): for atom in residue.atoms(): print(atom.unit_id()) # You can also filter the atoms in the same way. print('Iterating over specific atoms') for residue in structure.residues(chain='A', sequence=['G', 'C']): for atom in residue.atoms(name=['N1', 'C2']): print(atom.unit_id())
def get_structure(filename): if not os.path.exists(filename): mmCIFname = filename[-8:] print("Downloading " + mmCIFname) f = urllib.urlopen("https://files.rcsb.org/download/%s" % mmCIFname) myfile = f.read() with open(filename, 'w') as outfile: outfile.write(myfile) with open(filename, 'rb') as raw: structure = Cif(raw).structure() """All RNA bases are placed in the standard orientation. All Hydrogen atoms are inferred. Rotation matrix is calculated for each base.""" # structure.infer_hydrogens() return structure
def main(filename, limits): with open(filename, 'rb') as raw: structure = Cif(raw).structure() aa_mapping, aa_tree = generate_peptide_tree(structure, limits.get('residue', {})) rna_mapping, rna_tree = generate_rna_tree(structure, limits.get('nt', {})) # This produces a list of (rna_atom_index, aa_atom_index) # The query_ball_tree method goes through all points in rna_tree and finds # all points in aa_tree that have distance 5. It will return something for # all rna atoms, even those without any nearby aa atoms. results = enumerate(rna_tree.query_ball_tree(aa_tree, 5)) # Filter out all rna atoms that have nothing near by filtered = it.ifilter(lambda (r, a): a, results) # Map the results so we transform the rna atom to a residue mapped = it.imap(lambda (r, _): (rna_mapping[r], _), filtered) # Group the list by the residue grouped = it.groupby(mapped, lambda (r, _): r) # Display what we find for residue, nearby in grouped: # This creates a dictionary we use to count the number of near by # atoms. counts = coll.defaultdict(int) # Near by is a iterable of the form (residue, [indexes]) for (_, indexes) in nearby: for index in indexes: peptide = aa_mapping[index] counts[peptide] += 1 for peptide, count in counts.items(): print('%s: %s %s' % (residue.unit_id(), peptide.unit_id(), count))
def setUpClass(cls): print(cls.name) with open(os.path.join('files', cls.name + '.cif'), 'rb') as raw: cls.cif = Cif(raw) cls.structure = cls.cif.structure()
def setUpClass(cls): with open('files/1FJG.cif', 'rb') as raw: cls.structure = Cif(raw).structure() cls.structure.infer_hydrogens()
def setUpClass(cls): with open('test/files/cif/1GID.cif', 'rb') as raw: cls.structure = Cif(raw).structure()