Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.PDB.PDBIO.PDBIO Class Reference

List of all members.

Public Member Functions

def __init__
def set_structure
def save

Public Attributes

 use_model_flag
 structure

Private Member Functions

def _get_atom_line

Detailed Description

Write a Structure object (or a subset of a Structure object) as a PDB file.


Example:
    >>> p=PDBParser()
    >>> s=p.get_structure("1fat", "1fat.pdb")
    >>> io=PDBIO()
    >>> io.set_structure(s)
    >>> io.save("out.pdb")

Definition at line 47 of file PDBIO.py.


Constructor & Destructor Documentation

def Bio.PDB.PDBIO.PDBIO.__init__ (   self,
  use_model_flag = 0 
)
@param use_model_flag: if 1, force use of the MODEL record in output.
@type use_model_flag: int

Definition at line 59 of file PDBIO.py.

00059 
00060     def __init__(self, use_model_flag=0):
00061         """
00062         @param use_model_flag: if 1, force use of the MODEL record in output.
00063         @type use_model_flag: int
00064         """
00065         self.use_model_flag=use_model_flag
    

Member Function Documentation

def Bio.PDB.PDBIO.PDBIO._get_atom_line (   self,
  atom,
  hetfield,
  segid,
  atom_number,
  resname,
  resseq,
  icode,
  chain_id,
  charge = "  " 
) [private]
Returns an ATOM PDB string (PRIVATE).

Definition at line 69 of file PDBIO.py.

00069 
00070         resseq, icode, chain_id, charge="  "):
00071         """Returns an ATOM PDB string (PRIVATE)."""
00072         if hetfield!=" ":
00073             record_type="HETATM"
00074         else:
00075             record_type="ATOM  "
00076         if atom.element:
00077             element = atom.element.strip().upper()
00078             if element.capitalize() not in atom_weights:
00079                 raise ValueError("Unrecognised element %r" % atom.element)
00080             element = element.rjust(2)
00081         else:
00082             element = "  "
00083         name=atom.get_fullname()
00084         altloc=atom.get_altloc()
00085         x, y, z=atom.get_coord()
00086         bfactor=atom.get_bfactor()
00087         occupancy=atom.get_occupancy()
00088         args=(record_type, atom_number, name, altloc, resname, chain_id,
00089             resseq, icode, x, y, z, occupancy, bfactor, segid,
00090             element, charge)
00091         return _ATOM_FORMAT_STRING % args

Here is the caller graph for this function:

def Bio.PDB.PDBIO.PDBIO.save (   self,
  file,
  select = Select(),
  write_end = 0 
)
@param file: output file
@type file: string or filehandle 

@param select: selects which entities will be written.
@type select: 
    select hould have the following methods:
- accept_model(model)
- accept_chain(chain)
- accept_residue(residue)
- accept_atom(atom)
    These methods should return 1 if the entity
    is to be written out, 0 otherwise.

    Typically select is a subclass of L{Select}.

Definition at line 97 of file PDBIO.py.

00097 
00098     def save(self, file, select=Select(), write_end=0):
00099         """
00100         @param file: output file
00101         @type file: string or filehandle 
00102 
00103         @param select: selects which entities will be written.
00104         @type select: 
00105             select hould have the following methods:
00106                 - accept_model(model)
00107                 - accept_chain(chain)
00108                 - accept_residue(residue)
00109                 - accept_atom(atom)
00110             These methods should return 1 if the entity
00111             is to be written out, 0 otherwise.
00112 
00113             Typically select is a subclass of L{Select}.
00114         """
00115         get_atom_line=self._get_atom_line
00116         if isinstance(file, basestring):
00117             fp=open(file, "w")
00118             close_file=1
00119         else:
00120             # filehandle, I hope :-)
00121             fp=file
00122             close_file=0
00123         # multiple models?
00124         if len(self.structure)>1 or self.use_model_flag:
00125             model_flag=1
00126         else:
00127             model_flag=0
00128         for model in self.structure.get_list():
00129             if not select.accept_model(model):
00130                 continue
00131             # necessary for ENDMDL 
00132             # do not write ENDMDL if no residues were written
00133             # for this model
00134             model_residues_written=0
00135             atom_number=1
00136             if model_flag:
00137                 fp.write("MODEL      %s\n" % model.serial_num)
00138             for chain in model.get_list():
00139                 if not select.accept_chain(chain):
00140                     continue
00141                 chain_id=chain.get_id()
00142                 # necessary for TER 
00143                 # do not write TER if no residues were written
00144                 # for this chain
00145                 chain_residues_written=0
00146                 for residue in chain.get_unpacked_list():
00147                     if not select.accept_residue(residue):
00148                         continue
00149                     hetfield, resseq, icode=residue.get_id()
00150                     resname=residue.get_resname()  
00151                     segid=residue.get_segid()
00152                     for atom in residue.get_unpacked_list():
00153                         if select.accept_atom(atom):
00154                             chain_residues_written=1
00155                             model_residues_written=1
00156                             s=get_atom_line(atom, hetfield, segid, atom_number, resname,
00157                                 resseq, icode, chain_id)
00158                             fp.write(s)
00159                             atom_number=atom_number+1
00160                 if chain_residues_written:
00161                     fp.write("TER\n")
00162             if model_flag and model_residues_written:
00163                 fp.write("ENDMDL\n")
00164             if write_end:
00165                 fp.write('END\n')
00166         if close_file:
00167             fp.close()

Here is the call graph for this function:

def Bio.PDB.PDBIO.PDBIO.set_structure (   self,
  structure 
)

Definition at line 94 of file PDBIO.py.

00094 
00095     def set_structure(self, structure):
00096         self.structure=structure


Member Data Documentation

Definition at line 95 of file PDBIO.py.

Definition at line 64 of file PDBIO.py.


The documentation for this class was generated from the following file: