Esempio n. 1
0
 def _add_bonds(self):
     bonds = []
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name N").ix,
             s.atoms.select_atoms("name O").ix)
     ])
     bonds.extend([(r.atoms.select_atoms("name N").ix[0],
                    r.atoms.select_atoms("cbeta").ix[0])
                   for r in self.residues
                   if (r.resname != "GLY"
                       and r.resname in selection.ProteinSelection.prot_res)
                   ])
     bonds.extend([(r.atoms.select_atoms("cbeta").ix[0],
                    r.atoms.select_atoms("name O").ix[0])
                   for r in self.residues
                   if (r.resname != "GLY"
                       and r.resname in selection.ProteinSelection.prot_res)
                   ])
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name O").ix,
             s.atoms.select_atoms("name N").ix[1:])
         if s.residues.n_residues > 1
     ])
     self._topology.add_TopologyAttr(topologyattrs.Bonds(bonds))
     self._generate_from_topology()
Esempio n. 2
0
 def _add_bonds(self):
     bonds = []
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name P").ix,
             s.atoms.select_atoms("name C4'").ix)
     ])
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name C4'").ix,
             s.atoms.select_atoms("name C2'").ix)
     ])
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name C2'").ix,
             s.atoms.select_atoms("name H1").ix)
     ])
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name H1").ix,
             s.atoms.select_atoms("name H2").ix)
     ])
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name H2").ix,
             s.atoms.select_atoms("name H3").ix)
     ])
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("name C4'").ix[:-1],
             s.atoms.select_atoms("name P").ix[1:])
     ])
     self._topology.add_TopologyAttr(topologyattrs.Bonds(bonds))
     self._generate_from_topology()
Esempio n. 3
0
 def _add_bonds(self):
     bonds = []
     bonds.extend([
         _ for s in self.segments for _ in zip(
             s.atoms.select_atoms("calpha").ix,
             s.atoms.select_atoms("calpha").ix[1:])
     ])
     self._topology.add_TopologyAttr(topologyattrs.Bonds(bonds))
     self._generate_from_topology()
Esempio n. 4
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])
    )
Esempio n. 5
0
 def _add_bonds(self):
     positions = fmutils.AverageStructure(self.atu.atoms).run().result
     distmat = distance_array(positions, positions, backend="OpenMP")
     if self._rmin > 0.:
         a0, a1 = np.where((distmat >= self._rmin)
                           & (distmat <= self._rmax))
     else:
         a0, a1 = np.where((distmat > self._rmin) & (distmat <= self._rmax))
     bonds = topologyattrs.Bonds(
         set([(x, y) for x, y in zip(a0, a1) if y > x]))
     self._topology.add_TopologyAttr(bonds)
     self._generate_from_topology()
Esempio n. 6
0
 def _add_bonds(self):
     print(self.atu.bonds)
     positions = fmutils.AverageStructure(self.atu.atoms).run().result
     distmat = distance_array(positions, positions, backend="OpenMP")
     if self._rmin > 0.:
         a0, a1 = np.where((distmat >= self._rmin)
                           & (distmat <= self._rmax))
     else:
         print(self._rmax)
         a0, a1 = np.where((distmat > self._rmin) & (distmat <= self._rmax))
     skeleton_bonds = set([(skeleton[0].ix, skeleton[1].ix)
                           for skeleton in self.atu.bonds])
     rmax_bonds = set([(x, y) for x, y in zip(a0, a1) if y > x])
     all_bonds = skeleton_bonds.union(rmax_bonds)
     bonds = topologyattrs.Bonds(all_bonds)
     self._topology.add_TopologyAttr(bonds)
     self._generate_from_topology()
Esempio n. 7
0
    def tune_topology(self, fluctdiff):
        """

        Parameters
        ----------
        fluctdiff: pd.Series
            RMS fluctuation diffrence between QHA & NMA

        Returns
        -------
            Writes new topology and parameter files and return the trimmed universe
        """
        new_bonds, bonds_trimmed = self.trim_get_new_bondlist_write_prm(
            fluctdiff)
        bonds = topologyattrs.Bonds(self.get_atm_idx_aft_trim(new_bonds))
        self.universe._topology.add_TopologyAttr(bonds)
        self.universe._generate_from_topology()
        return self.trim_write_topology_files()
Esempio n. 8
0
    def __new__(cls,
                have_bonds=True,
                have_masses=True,
                have_molnums=True,
                have_charges=True,
                is_triclinic=False):
        # box:
        a = 10.0  # edge length
        tfac = 0.1  # factor for box vector shift of triclinic boxes (~84°)
        if is_triclinic:
            box = triclinic_box([a, 0.0, 0.0], [a * tfac, a, 0.0],
                                [a * tfac, a * tfac, a])
        else:
            box = np.array([a, a, a, 90.0, 90.0, 90.0], dtype=np.float32)

        # number of atoms, residues, and segments:
        n_atoms = 47
        n_residues = 15
        n_segments = 6

        # resindices:
        residx = np.empty(n_atoms, dtype=np.int64)
        # type A
        rix = 0
        for i in range(0, 3, 1):
            residx[i] = rix
            rix += 1
        # type B
        for i in range(3, 15, 3):
            residx[i:i + 3] = rix
            rix += 1
        # type C & D
        for i in range(15, 47, 4):
            residx[i:i + 4] = rix
            rix += 1

        # segindices:
        segidx = np.empty(n_residues, dtype=np.int64)
        segidx[0:3] = 0
        segidx[3:7] = 1
        segidx[7:9] = 2
        segidx[9:11] = 3
        segidx[11:13] = 4
        segidx[13:15] = 5

        # universe:
        u = mda.Universe.empty(
            # topology things
            n_atoms=n_atoms,
            n_residues=n_residues,
            n_segments=n_segments,
            atom_resindex=residx,
            residue_segindex=segidx,
            # trajectory things
            trajectory=True,
            velocities=False,
            forces=False,
        )

        # resnames: we always want those for selection purposes
        resnames = ['A'] * 3
        resnames += ['B'] * 4
        resnames += ['C'] * 2
        resnames += ['D1', 'D2'] * 3
        u.add_TopologyAttr(topologyattrs.Resnames(resnames))

        # moltypes: we always want those for selection purposes
        moltypes = ['A'] * 3
        moltypes += ['B'] * 4
        moltypes += ['C'] * 2
        moltypes += ['D'] * 6
        u.add_TopologyAttr(topologyattrs.Moltypes(moltypes))

        # trajectory:
        ts = u.trajectory.ts
        ts.frame = 0
        ts.dimensions = box

        # positions:
        relpos = np.empty((n_atoms, 3), dtype=np.float32)
        # type A
        relpos[0:3, :] = np.array(
            [[0.5, 0.5, 0.5], [1.4, 0.5, 0.5], [2.1, 0.5, 0.5]],
            dtype=np.float32)
        # type B
        relpos[3:15, :] = np.array(
            [[0.1, 0.1, 0.2], [0.1, 0.1, 0.1], [0.2, 0.1, 0.1],
             [-0.05, 0.2, 0.05], [0.05, 0.2, 0.05], [0.05, 0.2, 0.95],
             [-0.2, -0.9, 1.05], [-0.2, 0.1, -0.05], [-0.1, 0.1, -0.05],
             [0.95, 0.2, 0.25], [0.95, 0.2, 0.15], [1.05, 0.2, 0.15]],
            dtype=np.float32)
        # type C
        relpos[15:23, :] = np.array(
            [[0.4, 0.95, 1.05], [0.4, 0.95, 0.95], [0.4, 0.05, 0.95],
             [0.4, 0.05, 1.05], [0.6, 0.05, 0.25], [0.6, 0.05, 0.15],
             [0.6, 0.15, 0.15], [0.6, 0.15, 0.25]],
            dtype=np.float32)
        # type D
        relpos[23:47, :] = np.array(
            [[0.2, 0.7, 0.8], [0.3, 0.7, 0.8], [0.4, 0.7, 0.8],
             [0.5, 0.7, 0.8], [0.6, 0.7, 0.8], [0.7, 0.7, 0.8],
             [0.8, 0.7, 0.8], [0.9, 0.7, 0.8], [0.66, 0.75, 0.7],
             [0.76, 0.75, 0.7], [0.86, 0.75, 0.7], [0.96, 0.75, 0.7],
             [0.06, 0.75, 0.7], [0.16, 0.75, 0.7], [0.26, 0.75, 0.7],
             [0.36, 0.75, 0.7], [1.14, 0.65, -0.4], [1.04, 0.65, -0.4],
             [0.94, 0.65, -0.4], [0.84, 0.65, -0.4], [0.74, 0.65, -0.4],
             [0.64, 0.65, -0.4], [0.54, 0.65, -0.4], [0.44, 0.65, -0.4]],
            dtype=np.float32)
        # make a copy, we need the original later
        _relpos = relpos.copy()
        # apply y- and z-dependent shift of x and y coords for triclinic boxes:
        if is_triclinic:
            # x-coord shift depends on y- and z-coords
            _relpos[:, 0] += tfac * _relpos[:, 1:].sum(axis=1)
            # y-coord shift depends on z-coords only
            _relpos[:, 1] += tfac * _relpos[:, 2]
        # scale relative to absolute positions:
        ts.positions = (_relpos * np.array([a, a, a])).astype(np.float32)

        # bonds:
        if have_bonds:
            bonds = []
            # type A has no bonds
            #type B
            for base in range(3, 15, 3):
                for i in range(2):
                    bonds.append((base + i, base + i + 1))
            # type C
            for base in range(15, 23, 4):
                for i in range(3):
                    bonds.append((base + i, base + i + 1))
                bonds.append((0 + base, 3 + base))
            # type D
            for base in range(23, 47, 8):
                for i in range(7):
                    bonds.append((base + i, base + i + 1))
            u.add_TopologyAttr(topologyattrs.Bonds(bonds))

        # masses:
        if have_masses:
            # masses are all set to 1 so that one can cross-check the results of
            # reference='com' with reference='cog' unwrapping
            masses = np.ones(n_atoms)
            u.add_TopologyAttr(topologyattrs.Masses(masses))

        # molnums:
        if have_molnums:
            molnums = [0, 1, 2]
            molnums += [3, 4, 5, 6]
            molnums += [7, 8]
            molnums += [9, 9, 10, 10, 11, 11]
            u.add_TopologyAttr(topologyattrs.Molnums(molnums))

        # charges:
        if have_charges:
            # type A
            charges = [2] * 3
            # type B
            charges += [-0.5] * 12
            # type C
            charges += [-1.5] * 8
            # type C
            charges += [0.5] * 24
            u.add_TopologyAttr(topologyattrs.Charges(charges))

        # shamelessly monkey-patch some custom universe attributes:
        u._is_triclinic = is_triclinic
        u._relpos = relpos
        u._tfac = tfac
        u._box_edge = a
        # bind custom methods to universe:
        u.unwrapped_coords = cls.unwrapped_coords.__get__(u)
        u.wrapped_coords = cls.wrapped_coords.__get__(u)
        u.center = cls.center.__get__(u)

        return u
Esempio n. 9
0
 def _add_bonds(self):
     self._topology.add_TopologyAttr(topologyattrs.Bonds([]))
     self._generate_from_topology()