def get_molecule(pdb):
    txt = open(pdb, 'r').read()
    txt = pdbtext.strip_other_nmr_models(txt)
    txt = pdbtext.strip_lines(txt, lambda l: l.startswith('ANISOU'))
    txt = pdbtext.strip_lines(txt, lambda l: l.startswith('CONECT'))
    txt = pdbtext.strip_lines(txt, lambda l: l.startswith('MASTER'))
    txt = pdbtext.strip_alternative_atoms(txt)
    bare_fname = util.temp_fname('.pdb')
    open(bare_fname, 'w').write(txt)
    mol = pdbstruct.Molecule(bare_fname)
    if os.path.isfile(bare_fname):
        os.remove(bare_fname)
    return mol
 def make_mol(self, res_type, atom_type):
     mol = pdbstruct.Molecule()
     element = ""
     for c in atom_type[:2]:
         if not c.isdigit() and c != " ":
             element += c
     i_res = 1
     for i in range(self.n):
         for j in range(self.n):
             for k in range(self.n):
                 if not (self.is_excluded_or_drilled(i, j, k)):
                     hollow_atom = pdbstruct.Atom()
                     hollow_atom.pos = self.pos(i, j, k)
                     hollow_atom.type = atom_type
                     hollow_atom.element = element
                     hollow_atom.res_type = res_type
                     hollow_atom.res_num = i_res
                     hollow_atom.num = i_res
                     mol.insert_atom(hollow_atom)
                     i_res += 1
     return mol
 def make_mol(self, res_type, atom_type):
     mol = pdbstruct.Molecule()
     element = ""
     for c in atom_type[:2]:
         if not c.isdigit() and c != " ":
             element += c
     i_res = 1
     for i in range(self.n):
         for j in range(self.n):
             for k in range(self.n):
                 l = i * self.n_sq + j * self.n + k
                 if self.array[l]:
                     hollow_atom = pdbstruct.Atom()
                     hollow_atom.pos = self.pos(i, j, k)
                     hollow_atom.type = atom_type
                     hollow_atom.element = element
                     hollow_atom.res_type = res_type
                     hollow_atom.res_num = i_res
                     hollow_atom.num = i_res
                     mol.insert_atom(hollow_atom)
                     i_res += 1
     return mol
示例#4
0
               
  -n n_sphere  number of points used in generating the spherical
               dot-density for the calculation (default=960). The 
               more points, the more accurate (but slower) the 
               calculation. 

  """
  import sys
  import getopt
  opts, args = getopt.getopt(sys.argv[1:], "n:")

  if len(args) == 0:
    print usage
    sys.exit(1)
    
  mol = pdbstruct.Molecule(args[0])
  atoms = mol.atoms()
  pdbstruct.add_radii(atoms)

  n_sphere = 960
  for o, a in opts:
    if '-n' in o:
      n_sphere = int(a)
      print "Points on sphere: ", n_sphere

  asas = calculate_asa(atoms, 1.4, n_sphere)
  print "%.1f angstrom squared." % sum(asas)

  if len(args) > 1:
    for asa, atom in zip(asas, atoms):
      atom.bfactor = asa
if __name__ == "__main__":
    usage = \
    """
  Calculates the volume of the atoms in a PDB file.
  Copyright (c) 2007 Bosco Ho.  

  Usage: volume.py in_pdb [spacing]
  
  -spacing    the spacing in the grid used to calculate the 
              volume grid (default=0.5). The smaller value,
              the more accurate, but slower.
  """
    import sys
    if len(sys.argv) < 2:
        print usage
        sys.exit(1)

    spacing = 0.5
    if len(sys.argv) > 2:
        spacing = float(sys.argv[2])

    load_psyco_if_in_system()

    mol = pdbstruct.Molecule(sys.argv[1])
    atoms = mol.atoms()
    pdbstruct.add_radii(atoms)

    print "%d atoms in input pdb file" % len(atoms)
    volume(atoms, spacing, sys.argv[1].replace('.pdb', '.grid.pdb'))