Exemple #1
0
    def _conclude(self):
        print("Concluding...")
        results = np.vstack(self._results)
        Mup = results[:, 0]
        Mdw = results[:, 1]
        zlimup = results[:, 2].flatten()
        zlimdw = results[:, 3].flatten()
        dim = np.vstack(results[:, 4])

        N = self.N
        df = Universe.empty(n_atoms=N,
                            n_residues=N,
                            atom_resindex=np.arange(N),
                            trajectory=True)

        df.add_TopologyAttr('resname', ['O'] * N)
        df.add_TopologyAttr('name', ['O'] * N)
        df.add_TopologyAttr('resid', np.arange(N) + 1)

        nframes = len(dim)
        fac = np.zeros((nframes, N, 3))
        df.load_new(fac, order='fac')
        df.trajectory[0].dt = self.dt

        for i, ts in enumerate(df.trajectory):
            df.trajectory[i].dimensions = dim[i]

        PLacyl = df.copy()
        Deep = df.copy()
        TGacyl = df.copy()
        TGglyc = df.copy()

        xxyy = []
        for i in range(len(df.trajectory)):
            xarray = np.arange(0, dim[i][0], self.dx)
            yarray = np.arange(0, dim[i][1], self.dy)
            xx, yy = np.meshgrid(xarray, yarray)
            xxyy.append([xx, yy])

        ### PL acyl
        PLacyls = []
        for i, ts in enumerate(PLacyl.trajectory):
            num = 0
            bA = (1e3 <= Mup[i]) & (Mup[i] < 1e6)
            PLacyls.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                PLacyl.atoms[num].position = np.array([y1, x1, zlimup[i]])
                num += 1

            bA = (1e3 <= Mdw[i]) & (Mdw[i] < 1e6)
            PLacyls.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                PLacyl.atoms[num].position = np.array([y1, x1, zlimdw[i]])
                num += 1

        ### Deep
        Deeps = []
        for i, ts in enumerate(Deep.trajectory):
            num = 0
            bA = (Mup[i] == 0)
            Deeps.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                Deep.atoms[num].position = np.array([y1, x1, zlimup[i]])
                num += 1

            bA = (Mdw[i] == 0)
            Deeps.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                Deep.atoms[num].position = np.array([y1, x1, zlimdw[i]])
                num += 1

        ### TG glycerol
        TGglycs = []
        for i, ts in enumerate(TGglyc.trajectory):
            num = 0
            bA = (1 <= Mup[i]) & (Mup[i] < 1e3)
            TGglycs.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                TGglyc.atoms[num].position = np.array([y1, x1, zlimup[i]])
                num += 1

            bA = (1 <= Mdw[i]) & (Mdw[i] < 1e3)
            TGglycs.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                TGglyc.atoms[num].position = np.array([y1, x1, zlimdw[i]])
                num += 1

        ### TG acyl
        TGacyls = []
        for i, ts in enumerate(TGacyl.trajectory):
            num = 0
            bA = (0 < Mup[i]) & (Mup[i] < 1)
            TGacyls.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                TGacyl.atoms[num].position = np.array([y1, x1, zlimup[i]])
                num += 1

            bA = (0 < Mdw[i]) & (Mdw[i] < 1)
            TGacyls.append(bA.astype(int))
            for x1, y1 in zip(xxyy[i][0][bA], xxyy[i][1][bA]):
                TGacyl.atoms[num].position = np.array([y1, x1, zlimdw[i]])
                num += 1

        def write(fname, u):
            u.trajectory[-1]
            u.atoms.write(fname + '.gro')
            with mda.Writer(fname + '.xtc', u.atoms.n_atoms) as W:
                for ts in u.trajectory:
                    W.write(u.atoms)

        write('PLacyl', PLacyl)
        write('Deep', Deep)
        write('TGglyc', TGglyc)
        write('TGacyl', TGacyl)

        PD = PackingDefect()
        PD.defect_size(PLacyls,
                       fname='PLacyl.dat',
                       nbins=self.nbins,
                       bin_max=self.bin_max)
        PD.defect_size(Deeps,
                       fname='Deep.dat',
                       nbins=self.nbins,
                       bin_max=self.bin_max)
        PD.defect_size(TGglycs,
                       fname='TGglyc.dat',
                       nbins=self.nbins,
                       bin_max=self.bin_max)
        PD.defect_size(TGacyls,
                       fname='TGacyl.dat',
                       nbins=self.nbins,
                       bin_max=self.bin_max)
Exemple #2
0
    def _conclude(self):
        print("Concluding...")
        results = np.vstack(self._results)
        Mup = results[:, 0]
        Mdw = results[:, 1]
        zlimup = results[:, 2].flatten()
        zlimdw = results[:, 3].flatten()
        dim = np.vstack(results[:, 4])

        N = self.N
        df = Universe.empty(n_atoms=N,
                            n_residues=N,
                            atom_resindex=np.arange(N),
                            residue_segindex=[0] * N,
                            trajectory=True)

        df.add_TopologyAttr('resname', ['O'] * N)
        df.add_TopologyAttr('name', ['O'] * N)
        df.add_TopologyAttr('resid', np.arange(N) + 1)

        nframes = len(dim)
        fac = np.zeros((nframes, N, 3))
        df.load_new(fac, order='fac')
        df.trajectory[0].dt = self.dt

        for i, ts in enumerate(df.trajectory):
            df.trajectory[i].dimensions = dim[i]

        defects = ['Deep', 'PLacyl', 'TGglyc', 'TGacyl']

        defect_uni = {}
        defect_clu = {}
        for d in defects:
            defect_uni[d] = df.copy()
        for d in defects:
            defect_clu[d] = []
        defect_thr = {'Deep': 0, 'PLacyl': 1, 'TGglyc': 2, 'TGacyl': 3}

        for d in defects:
            for i, ts in enumerate(defect_uni[d].trajectory):
                num = 0

                bA = (Mup[i] == defect_thr[d])
                defect_clu[d].append(bA.astype(int))
                ind = np.where(bA)
                xs = ind[1]
                ys = ind[0]

                for x1, y1 in zip(xs, ys):
                    pos = np.array([x1, y1, zlimup[i]])
                    defect_uni[d].atoms[num].position = pos
                    num += 1

                bA = (Mdw[i] == defect_thr[d])
                defect_clu[d].append(bA.astype(int))
                ind = np.where(bA)
                xs = ind[1]
                ys = ind[0]

                for x1, y1 in zip(xs, ys):
                    pos = np.array([x1, y1, zlimdw[i]])
                    defect_uni[d].atoms[num].position = pos
                    num += 1

        ### DEFECT LOCALIZATION
        for d in defects:
            u = defect_uni[d]
            u.trajectory[-1]
            u.atoms.write(self.prefix + d + '2.gro')
            with mda.Writer(self.prefix + d + '2.xtc', u.atoms.n_atoms) as W:
                for ts in u.trajectory:
                    W.write(u.atoms)

        ### DEFECT CLUSTER
        PD = PackingDefect2()
        for d in defects:
            PD.defect_size(defect_clu[d],
                           fname=self.prefix + d + '2.dat',
                           nbins=self.nbins,
                           bin_max=self.bin_max)