ensemble_hic/analysis_functions.py
def write_ensemble(X, filename, mol_ranges=None, center=True):
    """Writes a structure ensemble to a PDB file.

    :param X: coordinates of a structure ensemble
    :type X: :class:`numpy.ndarray`

    :param filename: file name of output PDB file
    :type filename: str

    :param mol_ranges: if writing structures consisting of several molecules, this
                       specifies start and end beads of the single molecules. Example:                       [0, 9, 19] for two molecules of 10 beads each
    :type mol_ranges: :class:`numpy.ndarray`

    :param center: if True, aligns the centers of mass of all structures
    :type center: bool
    """ 

    from csb.bio.structure import Atom, ProteinResidue, Chain, Structure, Ensemble
    from csb.bio.sequence import ProteinAlphabet

    if center:
        X -= X.mean(1)[:,None,:]

    if mol_ranges is None:
        mol_ranges = np.array([0, X.shape[1]])
    
    ensemble = Ensemble()

    for i, x in enumerate(X):
        structure = Structure('')
        structure.model_id = i + 1

        mol_coordinates = np.array([x[start:end]
                                    for start, end in zip(mol_ranges[:-1],
                                                          mol_ranges[1:])])
        for j, mol in enumerate(mol_coordinates):
            structure.chains.append(Chain(chr(65 + j)))

            for k, y in enumerate(mol):
                atom = Atom(k+1, 'CA', 'C', y)
                residue = ProteinResidue(k, 'ALA')
                residue.atoms.append(atom)
                structure.chains[chr(65 + j)].residues.append(residue)

        ensemble.models.append(structure)
    ensemble.to_pdb(filename)
Writes a structure ensemble to a PDB file.

    :param X: coordinates of a structure ensemble
    :type X: :class:`numpy.ndarray`

    :param filename: file name of output PDB file
    :type filename: str

    :param mol_ranges: if writing structures consisting of several molecules, this
                       specifies start and end beads of the single molecules. Example:                       [0, 9, 19] for two molecules of 10 beads each
    :type mol_ranges: :class:`numpy.ndarray`

    :param center: if True, aligns the centers of mass of all structures
    :type center: bool
    
Writes a structure ensemble to a PDB file.
Writes a structure ensemble to a PDB file .
def write_ensemble(X, filename, mol_ranges=None, center=True):
    from csb.bio.structure import Atom, ProteinResidue, Chain, Structure, Ensemble
    from csb.bio.sequence import ProteinAlphabet
    if center:
        X -= X.mean(1)[:,None,:]
    if mol_ranges is None:
        mol_ranges = np.array([0, X.shape[1]])
    ensemble = Ensemble()
    for i, x in enumerate(X):
        structure = Structure('')
        structure.model_id = i + 1
        mol_coordinates = np.array([x[start:end]
                                    for start, end in zip(mol_ranges[:-1],
                                                          mol_ranges[1:])])
        for j, mol in enumerate(mol_coordinates):
            structure.chains.append(Chain(chr(65 + j)))
            for k, y in enumerate(mol):
                atom = Atom(k+1, 'CA', 'C', y)
                residue = ProteinResidue(k, 'ALA')
                residue.atoms.append(atom)
                structure.chains[chr(65 + j)].residues.append(residue)
        ensemble.models.append(structure)
    ensemble.to_pdb(filename)
def write_ensemble ( X , filename , mol_ranges = None , center = True ) : from csb . bio . structure import Atom , ProteinResidue , Chain , Structure , Ensemble from csb . bio . sequence import ProteinAlphabet if center : X -= X . mean ( 1 ) [ : , None , : ] if mol_ranges is None : mol_ranges = np . array ( [ 0 , X . shape [ 1 ] ] ) ensemble = Ensemble ( ) for i , x in enumerate ( X ) : structure = Structure ( '' ) structure . model_id = i + 1 mol_coordinates = np . array ( [ x [ start : end ] for start , end in zip ( mol_ranges [ : - 1 ] , mol_ranges [ 1 : ] ) ] ) for j , mol in enumerate ( mol_coordinates ) : structure . chains . append ( Chain ( chr ( 65 + j ) ) ) for k , y in enumerate ( mol ) : atom = Atom ( k + 1 , 'CA' , 'C' , y ) residue = ProteinResidue ( k , 'ALA' ) residue . atoms . append ( atom ) structure . chains [ chr ( 65 + j ) ] . residues . append ( residue ) ensemble . models . append ( structure ) ensemble . to_pdb ( filename )
Writes a structure ensemble to a PDB file.
Writes a structure ensemble to a PDB file .
"""Writes a structure ensemble to a PDB file.

    :param X: coordinates of a structure ensemble
    :type X: :class:`numpy.ndarray`

    :param filename: file name of output PDB file
    :type filename: str

    :param mol_ranges: if writing structures consisting of several molecules, this
                       specifies start and end beads of the single molecules. Example:                       [0, 9, 19] for two molecules of 10 beads each
    :type mol_ranges: :class:`numpy.ndarray`

    :param center: if True, aligns the centers of mass of all structures
    :type center: bool
    """
X
coordinates of a structure ensemble
coordinates of a structure ensemble
filename
file name of output PDB file
file name of output PDB file
mol_ranges
if writing structures consisting of several molecules, this
specifies start and end beads of the single molecules. Example:                       [0, 9, 19] for two molecules of 10 beads each
if writing structures consisting of several molecules this specifies start and end beads of the single molecules . Example : [ 0 9 19 ] for two molecules of 10 beads each
center
if True, aligns the centers of mass of all structures
if True aligns the centers of mass of all structures