def save_structures(fpath, structures, dat):
    """
    Slightly different to the save routines in PDBD module; each structure
    has the same "internal" chainID values, and structures are separated into
    PDB 'MODEL' sections. We assume structures are lists of monomer ids.

    Args:
      fpath (string): path to PDB file for output
      structures (list of integer lists): sublists are individual structures, sublist elements are molecule indices for structure members

    Returns:
      list of integer lists, with each sublist denoting a trimer-of-dimers structure and sublist members denoting molecules indices in that structure
    """
    chains = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789'
    f = open(fpath, 'w')
    serial = 1
    for structure in structures:
        chain_i = 0
        serial = 1  # for if we wish to reset count each time (e.g. lots of structures as in the capsid!)
        print >> f, 'MODEL'
        for monomer_i in structure:
            for subunit_i in dat.monomers[monomer_i]:
                for a in dat.subunits[subunit_i]:
                    a2 = dict(a)  # modify a copy of the data, not the original
                    a2['chainID'] = chains[chain_i % len(chains)]

                    a2['serial'] = serial  # change this to retain original serial?
                    serial += 1

                    print >> f, PDB.MakePDBAtomLine(a2)
                print >> f, 'TER'
            chain_i += 1
        print >> f, 'ENDMDL'
    f.close()
예제 #2
0
def print_PDB(f, atoms, bonds, unit_length=None):
    """
	Print geometrical information to PDB file format for visualization.

	Args:
		f (file) : output destination
		atoms (list of PDB-style atom) : vertices
		bonds (list of integer pairs) : vertex connections
		unit_length (integer) : number of consecutive vertices in a notional geometrical unit

	Returns:
		Nothing
	"""
    conect_format = 'CONECT%5d%5d'

    if unit_length == None:
        unit_length = len(atoms)

    counter = 0
    for a in atoms:
        if (counter > 0) and (counter % unit_length == 0):
            print('TER   ', file=f)
        line = PDB.MakePDBAtomLine(a)
        print(line, file=f)
        counter += 1

    print('TER   ', file=f)

    for b in bonds:
        line = conect_format % (b[0], b[1])
        print(line, file=f)
예제 #3
0
elif action == 'recentre':
    new_molecules = recentre(molecules)

elif action == 'extract_chains':
    # split param tokens into individual characters, if needed.
    chains = []
    for tok in params:
        chains += [c for c in tok if c not in ' \t\n\r']
    new_molecules = extract_chains(molecules, chains)

elif action == 'extract_mols':
    if len(params) < 2:
        print_usage(sys.argv[0])
    new_molecules = extract_mols(molecules, int(params[0]),
                                 [int(mol_i) for mol_i in params[1:]])

elif action == 'filter':
    new_molecules = filter_molecules(molecules, params)

elif action == 'scale':
    new_molecules = scale_molecules(molecules, float(params[0]))

#
# Print new_molecules
#
for mol in new_molecules:
    for a in mol:
        outline = PDB.MakePDBAtomLine(a)
        print outline
    print 'TER   '