def to_pdb(structure, filename, contigs=None, annotations=None,<EOL>indices=None, special_bins=None):
n = len(structure)<EOL>letters = (string.ascii_uppercase + string.ascii_lowercase +<EOL>string.digits + string.punctuation) * int(n / <NUM_LIT> + <NUM_LIT:1>)<EOL>if contigs is None:<EOL><INDENT>contigs = np.ones(n + <NUM_LIT:1>)<EOL><DEDENT>if annotations is None:<EOL><INDENT>annotations = np.zeros(n + <NUM_LIT:1>)<EOL><DEDENT>if indices is None:<EOL><INDENT>indices = range(n + <NUM_LIT:1>)<EOL><DEDENT>if special_bins is None:<EOL><INDENT>special_bins = np.zeros(n + <NUM_LIT:1>)<EOL><DEDENT>structure_shapes_match = structure.shape[<NUM_LIT:0>] == structure.shape[<NUM_LIT:1>]<EOL>if isinstance(structure, np.ndarray) and structure_shapes_match:<EOL><INDENT>structure = (to_structure(structure))<EOL><DEDENT>X, Y, Z = (structure[:, i] for i in range(<NUM_LIT:3>))<EOL>Xmax, Ymax, Zmax = (np.max(np.abs(Xi)) for Xi in (X, Y, Z))<EOL>X *= <NUM_LIT> / Xmax<EOL>Y *= <NUM_LIT> / Ymax<EOL>Z *= <NUM_LIT> / Zmax<EOL>X = np.around(X, <NUM_LIT:3>)<EOL>Y = np.around(Y, <NUM_LIT:3>)<EOL>Z = np.around(Z, <NUM_LIT:3>)<EOL>reference = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>with open(filename, '<STR_LIT:w>') as f:<EOL><INDENT>for i in range(<NUM_LIT:1>, n):<EOL><INDENT>line = "<STR_LIT>"  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += str(i).rjust(<NUM_LIT:5>)  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += reference[special_bins[i]].rjust(<NUM_LIT:4>)  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += "<STR_LIT>"  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += letters[int(contigs[indices[i]] - <NUM_LIT:1>)<EOL>]  <EOL>line += str(i).rjust(<NUM_LIT:4>)  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += str(X[i]).rjust(<NUM_LIT:8>)  <EOL>line += str(Y[i]).rjust(<NUM_LIT:8>)  <EOL>line += str(Z[i]).rjust(<NUM_LIT:8>)  <EOL>line += "<STR_LIT>".rjust(<NUM_LIT:6>)  <EOL>line += str(annotations[i - <NUM_LIT:1>]).rjust(<NUM_LIT:6>)<EOL>line += "<STR_LIT:U+0020>"  <EOL>line += "<STR_LIT:U+0020>"  <EOL>line += "<STR_LIT:O>".rjust(<NUM_LIT:2>)  <EOL>line += "<STR_LIT:\n>"<EOL>f.write(line)<EOL><DEDENT><DEDENT>
From a structure (or matrix) generate the corresponding pdb file
    representing each chain as a contig/chromosome and filling the occupancy
    field with a custom annotation. If the matrix has been trimmed somewhat,
    remaining indices may be specified.