Exemple #1
0
def make_names(size):
    """Atom names AAA -> ZZZ (all unique)"""
    import MDAnalysis.core.topologyattrs as ta
    na, nr, ns = size
    # produces, AAA, AAB, AAC, ABA etc
    names = itertools.product(*[string.uppercase] * 3)
    return ta.Atomnames(
        np.array(['{}'.format(''.join(next(names))) for _ in range(na)],
                 dtype=object))
Exemple #2
0
def refTop():
    return topology.Topology(
        3, 2, 2,
        attrs = [
            ta.Atomnames(TA_FILLER[object]),
            ta.Masses(TA_FILLER[float]),
            ta.Resids(TA_FILLER[int]),
            ta.Bonds(TA_FILLER['bond']),
        ],
        atom_resindex=np.array([0, 0, 1]),
        residue_segindex=np.array([0, 1])
    )
Exemple #3
0
 def setUp(self):
     names = self.names = ta.Atomnames(
         np.array(['A', 'B', 'C'], dtype=object))
     types = self.types = ta.Atomtypes(np.array(['X', 'Y', 'Z'],
                                                dtype=object),
                                       guessed=True)
     resids = self.resids = ta.Resids(np.array([1]))
     resnames = self.resnames = ta.Resnames(np.array(['ABC'], dtype=object),
                                            guessed=True)
     self.top = Topology(n_atoms=3,
                         n_res=1,
                         attrs=[names, types, resids, resnames])
Exemple #4
0
def rename_universe(universe):
    """Rename the atoms and residues within a universe.

    Standardizes naming of the universe by renaming atoms and residues based
    upon the number of segments. Atoms are labeled as 'A001', 'A002', 'A003',
    ..., 'A999' for the first segment, and 'B001', 'B002', 'B003', ..., 'B999'
    for the second segment. Residues are named in a similar fashion according to
    their segment.

    Parameters
    ----------
    universe : :class:`~MDAnalysis.Universe`
        A collection of atoms in a universe.

    Returns
    -------
    :class:`~MDAnalysis.Universe`
        The universe with renamed residues and atoms.
    """
    logger.info("Renaming atom names and atom types within the universe.")
    atomnames = np.array([
        "{}{:0>3d}".format(lett, i)
        for lett, segment in zip(string.ascii_uppercase, universe.segments)
        for i, _ in enumerate(segment.atoms, 1)
    ])
    resnames = np.array([
        "{}{:0>3d}".format(lett, i)
        for lett, segment in zip(string.ascii_uppercase, universe.segments)
        for i, _ in enumerate(segment.residues, 1)
    ])

    universe._topology.add_TopologyAttr(topologyattrs.Atomnames(atomnames))
    universe._topology.add_TopologyAttr(topologyattrs.Resnames(resnames))
    if not np.issubdtype(universe.atoms.types.dtype, np.int64):
        universe._topology.add_TopologyAttr(topologyattrs.Atomtypes(atomnames))
    universe._generate_from_topology()
    return universe
Exemple #5
0
    def _apply_map(self, mapping):
        """Apply the mapping scheme to the beads.

        Parameters
        ----------
        mapping : dict
            Mapping definitions per bead/

        Returns
        -------
        :class:`~MDAnalysis.core.topology.Topology` defining the new universe.
        """
        # Allocate arrays
        _beads = []
        atomnames = []
        atomids = []
        resids = []
        resnames = []
        segids = []
        charges = []
        masses = []

        residues = self.atu.atoms.split("residue")
        select_residues = enumerate(
            itertools.product(residues, viewitems(mapping)))
        for i, (res, (name, selection)) in select_residues:
            if name != "CB":
                bead = res.select_atoms(selection)
            else:
                bead = res.select_atoms(
                    selection.get(res.resname[0],
                                  "hsidechain and not name H*"))
            if bead:
                _beads.append(bead)
                atomnames.append(name)
                atomids.append(i)
                resids.append(bead.resids[0])
                resnames.append(bead.resnames[0])
                segids.append(bead.segids[0].split("_")[-1])
                try:
                    charges.append(bead.total_charge())
                except AttributeError:
                    charges.append(0.)
                masses.append(bead.total_mass())

        _beads = np.array(_beads)
        n_atoms = len(_beads)

        # Atom
        # _beads = topattrs._Beads(_beads)
        vdwradii = np.zeros_like(atomids)
        vdwradii = topologyattrs.Radii(vdwradii)
        atomids = topologyattrs.Atomids(np.asarray(atomids))
        atomnames = topologyattrs.Atomnames(
            np.asarray(atomnames, dtype=np.object))
        atomtypes = topologyattrs.Atomtypes(
            np.asarray(np.arange(n_atoms) + 100))
        charges = topologyattrs.Charges(np.asarray(charges))
        masses = topologyattrs.Masses(np.asarray(masses))

        # Residue
        # resids, resnames
        segids = np.asarray(segids, dtype=np.object)
        resids = np.asarray(resids)
        resnames = np.asarray(resnames, dtype=np.object)
        residx, (new_resids, new_resnames, new_segids) = topbase.change_squash(
            (resids, ), (resids, resnames, segids))

        # transform from atom:Rid to atom:Rix
        residueids = topologyattrs.Resids(new_resids)
        residuenums = topologyattrs.Resnums(new_resids.copy())
        residuenames = topologyattrs.Resnames(new_resnames)

        # Segment
        segidx, (perseg_segids, ) = topbase.change_squash((new_segids, ),
                                                          (new_segids, ))
        segids = topologyattrs.Segids(perseg_segids)

        # Setup topology
        top = topology.Topology(len(atomids),
                                len(new_resids),
                                len(segids),
                                attrs=[
                                    atomids, atomnames, atomtypes, charges,
                                    masses, vdwradii, residueids, residuenums,
                                    residuenames, segids
                                ],
                                atom_resindex=residx,
                                residue_segindex=segidx)
        return top
Exemple #6
0
 def names(self):
     return ta.Atomnames(np.array(['A', 'B', 'C'], dtype=object))