def _parseatoms(self, pdb): atoms = [] # translate list of atoms to MDAnalysis Atom. for iatom, atom in enumerate(pdb._atoms): # ATOM if len(atom.__dict__) == 10: atomname = atom.name atomtype = atom.element or guess_atom_type(atomname) resname = atom.resName resid = int(atom.resSeq) chain = atom.chainID.strip() # no empty segids (or Universe throws IndexError) segid = atom.segID.strip() or chain or "SYSTEM" mass = guess_atom_mass(atomname) charge = guess_atom_charge(atomname) bfactor = atom.tempFactor # occupancy = atom.occupancy altLoc = atom.altLoc atoms.append(Atom(iatom, atomname, atomtype, resname, resid, segid, mass, charge, bfactor=bfactor, serial=atom.serial, altLoc=altLoc)) # TER atoms #elif len(atom.__dict__) == 5: # pass # #atoms.append(None) self.structure["_atoms"] = atoms
def _parseatoms(self, pdb): atoms = [] # translate Bio.PDB atom objects to MDAnalysis Atom. for iatom, atom in enumerate(pdb.get_atoms()): residue = atom.parent chain_id = residue.parent.id atomname = atom.name atomtype = guess_atom_type(atomname) resname = residue.resname resid = int(residue.id[1]) # no empty segids (or Universe throws IndexError) segid = residue.get_segid().strip() or chain_id or "SYSTEM" mass = guess_atom_mass(atomname) charge = guess_atom_charge(atomname) bfactor = atom.bfactor # occupancy = atom.occupancy atoms.append( Atom(iatom, atomname, atomtype, resname, resid, segid, mass, charge, bfactor=bfactor)) return atoms
def parse(self): """Parse CRD file *filename* and return the dict `structure`. Only reads the list of atoms. :Returns: MDAnalysis internal *structure* dict .. SeeAlso:: The *structure* dict is defined in `MDAnalysis.topology` """ extformat = FORTRANReader( '2I10,2X,A8,2X,A8,3F20.10,2X,A8,2X,A8,F20.10') stdformat = FORTRANReader('2I5,1X,A4,1X,A4,3F10.5,1X,A4,1X,A4,F10.5') atoms = [] atom_serial = 0 with openany(self.filename) as crd: for linenum, line in enumerate(crd): # reading header if line.split()[0] == '*': continue elif line.split()[-1] == 'EXT' and bool(int( line.split()[0])) is True: r = extformat continue elif line.split()[0] == line.split( )[-1] and line.split()[0] != '*': r = stdformat continue # anything else should be an atom try: serial, TotRes, resName, name, x, y, z, chainID, resSeq, tempFactor = r.read( line) except: raise ValueError("Check CRD format at line {}: {}".format( linenum, line.rstrip())) atomtype = guess_atom_type(name) mass = guess_atom_mass(name) charge = guess_atom_charge(name) atoms.append( Atom(atom_serial, name, atomtype, resName, TotRes, chainID, mass, charge)) atom_serial += 1 structure = {} structure["_atoms"] = atoms return structure
def parse(self): """Parse CRD file *filename* and return the dict `structure`. Only reads the list of atoms. :Returns: MDAnalysis internal *structure* dict .. SeeAlso:: The *structure* dict is defined in `MDAnalysis.topology` """ extformat = FORTRANReader('2I10,2X,A8,2X,A8,3F20.10,2X,A8,2X,A8,F20.10') stdformat = FORTRANReader('2I5,1X,A4,1X,A4,3F10.5,1X,A4,1X,A4,F10.5') atoms = [] atom_serial = 0 with openany(self.filename) as crd: for linenum, line in enumerate(crd): # reading header if line.split()[0] == '*': continue elif line.split()[-1] == 'EXT' and bool(int(line.split()[0])) is True: r = extformat continue elif line.split()[0] == line.split()[-1] and line.split()[0] != '*': r = stdformat continue # anything else should be an atom try: serial, TotRes, resName, name, x, y, z, chainID, resSeq, tempFactor = r.read(line) except: raise ValueError("Check CRD format at line {}: {}".format( linenum, line.rstrip())) atomtype = guess_atom_type(name) mass = guess_atom_mass(name) charge = guess_atom_charge(name) atoms.append(Atom(atom_serial, name, atomtype, resName, TotRes, chainID, mass, charge)) atom_serial += 1 structure = {} structure["_atoms"] = atoms return structure
def _parseatoms_(self, pdb): atoms = [] # translate list of atoms to MDAnalysis Atom. for iatom, atom in enumerate(pdb._atoms): atomname = atom.name atomtype = atom.type # always set in PDBQT resname = atom.resName resid = int(atom.resSeq) chain = atom.chainID.strip() segid = chain or "SYSTEM" # no empty segids (or Universe throws IndexError) mass = guess_atom_mass(atomname) charge = float(atom.partialCharge) # always set in PDBQT bfactor = atom.tempFactor # occupancy = atom.occupancy atoms.append(Atom(iatom, atomname, atomtype, resname, resid, segid, mass, charge, bfactor=bfactor)) return atoms
def _parseatoms(self, pqr): atoms = [] # translate list of atoms to MDAnalysis Atom. for iatom, atom in enumerate(pqr._atoms): atomname = atom.name atomtype = guess_atom_type(atomname) resname = atom.resName resid = int(atom.resSeq) chain = atom.chainID.strip() # no empty segids (or Universe throws IndexError) segid = atom.segID.strip() or chain or "SYSTEM" mass = guess_atom_mass(atomname) charge = float(atom.charge) radius = atom.radius atoms.append(Atom(iatom, atomname, atomtype, resname, resid, segid, mass, charge, radius=radius)) return atoms
def _parseatoms(self, pdb): atoms = [] # translate Bio.PDB atom objects to MDAnalysis Atom. for iatom, atom in enumerate(pdb.get_atoms()): residue = atom.parent chain_id = residue.parent.id atomname = atom.name atomtype = guess_atom_type(atomname) resname = residue.resname resid = int(residue.id[1]) # no empty segids (or Universe throws IndexError) segid = residue.get_segid().strip() or chain_id or "SYSTEM" mass = guess_atom_mass(atomname) charge = guess_atom_charge(atomname) bfactor = atom.bfactor # occupancy = atom.occupancy atoms.append(Atom(iatom, atomname, atomtype, resname, resid, segid, mass, charge, bfactor=bfactor)) return atoms
def _parseatoms(self, pdb): atoms = [] # translate list of atoms to MDAnalysis Atom. for iatom, atom in enumerate(pdb._atoms): # ATOM if len(atom.__dict__) == 10: atomname = atom.name atomtype = atom.element or guess_atom_type(atomname) resname = atom.resName resid = int(atom.resSeq) chain = atom.chainID.strip() # no empty segids (or Universe throws IndexError) segid = atom.segID.strip() or chain or "SYSTEM" mass = guess_atom_mass(atomname) charge = guess_atom_charge(atomname) bfactor = atom.tempFactor # occupancy = atom.occupancy altLoc = atom.altLoc atoms.append( Atom(iatom, atomname, atomtype, resname, resid, segid, mass, charge, bfactor=bfactor, serial=atom.serial, altLoc=altLoc)) # TER atoms #elif len(atom.__dict__) == 5: # pass # #atoms.append(None) self.structure["_atoms"] = atoms
def parse(self, filename=None): """Parse MOL2 file *filename* and return the dict `structure`. Only reads the list of atoms. :Returns: MDAnalysis internal *structure* dict .. SeeAlso:: The *structure* dict is defined in :func:`MDAnalysis.topology.PSFParser.PSFParser`. """ if not filename: filename = self.filename blocks = [] with openany(filename) as f: for i, line in enumerate(f): # found new molecules if "@<TRIPOS>MOLECULE" in line: if len(blocks): break blocks.append({"start_line": i, "lines": []}) blocks[-1]["lines"].append(line) if not len(blocks): raise ValueError("The mol2 file '{}' needs to have at least one" " @<TRIPOS>MOLECULE block".format(filename)) block = blocks[0] sections = {} cursor = None for line in block["lines"]: if "@<TRIPOS>" in line: cursor = line.split("@<TRIPOS>")[1].strip().lower() sections[cursor] = [] continue elif line.startswith("#") or line == "\n": continue sections[cursor].append(line) atom_lines, bond_lines = sections["atom"], sections["bond"] if not len(atom_lines): raise ValueError("The mol2 block ({}:{}) has no atoms".format( os.path.basename(filename), block["start_line"])) if not len(bond_lines): raise ValueError("The mol2 block ({}:{}) has no bonds".format( os.path.basename(filename), block["start_line"])) atoms = [] for a in atom_lines: aid, name, x, y, z, atom_type, resid, resname, charge = a.split() aid = int(aid) - 1 #x, y, z = float(x), float(y), float(z) resid = int(resid) charge = float(charge) element = guess_atom_type(name) mass = guess_atom_mass(element) # atom type is sybl atom type atoms.append( Atom(aid, name, atom_type, resname, resid, "X", mass, charge)) #guess_atom_type(a.split()[1] bonds = [] bondorder = {} for b in bond_lines: # bond_type can be: 1, 2, am, ar bid, a0, a1, bond_type = b.split() a0, a1 = int(a0) - 1, int(a1) - 1 bond = tuple(sorted([a0, a1])) bondorder[bond] = bond_type bonds.append(bond) structure = {"_atoms": atoms, "_bonds": bonds, "_bondorder": bondorder} return structure
def parse(self, filename=None): """Parse MOL2 file *filename* and return the dict `structure`. Only reads the list of atoms. :Returns: MDAnalysis internal *structure* dict .. SeeAlso:: The *structure* dict is defined in :func:`MDAnalysis.topology.PSFParser.PSFParser`. """ if not filename: filename = self.filename blocks = [] with openany(filename) as f: for i, line in enumerate(f): # found new molecules if "@<TRIPOS>MOLECULE" in line: if len(blocks): break blocks.append({"start_line": i, "lines": []}) blocks[-1]["lines"].append(line) if not len(blocks): raise ValueError("The mol2 file '{}' needs to have at least one" " @<TRIPOS>MOLECULE block".format(filename)) block = blocks[0] sections = {} cursor = None for line in block["lines"]: if "@<TRIPOS>" in line: cursor = line.split("@<TRIPOS>")[1].strip().lower() sections[cursor] = [] continue elif line.startswith("#") or line == "\n": continue sections[cursor].append(line) atom_lines, bond_lines = sections["atom"], sections["bond"] if not len(atom_lines): raise ValueError("The mol2 block ({}:{}) has no atoms".format( os.path.basename(filename), block["start_line"])) if not len(bond_lines): raise ValueError("The mol2 block ({}:{}) has no bonds".format( os.path.basename(filename), block["start_line"])) atoms = [] for a in atom_lines: aid, name, x, y, z, atom_type, resid, resname, charge = a.split() aid = int(aid) - 1 #x, y, z = float(x), float(y), float(z) resid = int(resid) charge = float(charge) element = guess_atom_type(name) mass = guess_atom_mass(element) # atom type is sybl atom type atoms.append(Atom(aid, name, atom_type, resname, resid, "X", mass, charge)) #guess_atom_type(a.split()[1] bonds = [] bondorder = {} for b in bond_lines: # bond_type can be: 1, 2, am, ar bid, a0, a1, bond_type = b.split() a0, a1 = int(a0) - 1, int(a1) - 1 bond = tuple(sorted([a0, a1])) bondorder[bond] = bond_type bonds.append(bond) structure = {"_atoms": atoms, "_bonds": bonds, "_bondorder": bondorder} return structure