def dump_pdb(filename, molecule, atomnames=None, resnames=None, chain_ids=None, occupancies=None, betas=None):
with open(filename, "<STR_LIT:w>") as f:<EOL><INDENT>res_id = <NUM_LIT:1><EOL>old_resname = None<EOL>for i in range(molecule.size):<EOL><INDENT>symbol = periodic[molecule.numbers[i]].symbol<EOL>if atomnames is None:<EOL><INDENT>atomname = symbol<EOL><DEDENT>else:<EOL><INDENT>atomname = atomnames[i]<EOL><DEDENT>if resnames is None:<EOL><INDENT>resname = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>resname = resnames[i]<EOL><DEDENT>if resname != old_resname:<EOL><INDENT>res_id += <NUM_LIT:1><EOL><DEDENT>if chain_ids is None:<EOL><INDENT>chain_id = "<STR_LIT:A>"<EOL><DEDENT>else:<EOL><INDENT>chain_id = chain_ids[i]<EOL><DEDENT>if occupancies is None:<EOL><INDENT>occupancy = <NUM_LIT:1.0><EOL><DEDENT>else:<EOL><INDENT>occupancy = occupancies[i]<EOL><DEDENT>if betas is None:<EOL><INDENT>beta = <NUM_LIT:1.0><EOL><DEDENT>else:<EOL><INDENT>beta = betas[i]<EOL><DEDENT>print("<STR_LIT>" % (<EOL>i+<NUM_LIT:1>, atomname.ljust(<NUM_LIT:3>), resname.ljust(<NUM_LIT:3>), chain_id, res_id,<EOL>molecule.coordinates[i, <NUM_LIT:0>]/angstrom,<EOL>molecule.coordinates[i, <NUM_LIT:1>]/angstrom,<EOL>molecule.coordinates[i, <NUM_LIT:2>]/angstrom,<EOL>occupancy, beta, symbol.ljust(<NUM_LIT:2>)<EOL>), file=f)<EOL>old_resname = resname<EOL><DEDENT><DEDENT>
Writes a single molecule to a pdb file.

       This function is based on the pdb file specification:
       http://www.wwpdb.org/documentation/format32/sect9.html
       For convenience, the relevant table is copied and the character indexes are
       transformed to C-style (starting from zero)

       =======        ============  ==========   ==========================================
       COLUMNS        DATA  TYPE    FIELD        DEFINITION
       =======        ============  ==========   ==========================================
        0 -  5        Record name   "ATOM  "
        6 - 10        Integer       serial       Atom  serial number.
       12 - 15        Atom          name         Atom name.
       16             Character     altLoc       Alternate location indicator.
       17 - 19        Residue name  resName      Residue name.
       21             Character     chainID      Chain identifier.
       22 - 25        Integer       resSeq       Residue sequence number.
       26             AChar         iCode        Code for insertion of residues.
       30 - 37        Real(8.3)     x            Orthogonal coordinates for X in Angstroms.
       38 - 45        Real(8.3)     y            Orthogonal coordinates for Y in Angstroms.
       46 - 53        Real(8.3)     z            Orthogonal coordinates for Z in Angstroms.
       54 - 59        Real(6.2)     occupancy    Occupancy.
       60 - 65        Real(6.2)     tempFactor   Temperature  factor.
       76 - 77        LString(2)    element      Element symbol, right-justified.
       78 - 79        LString(2)    charge       Charge  on the atom.
       =======        ============  ==========   ==========================================