Пример #1
0
def drawatoms(atoms, members=None):
    s = ""
    if members is None:
        for a in atoms:
            s += yp.Circle(a)
    else:
        for i in members:
            s += yp.Circle(atoms[i])
    return s
Пример #2
0
def hook6(lattice):
    global nwateratoms
    lattice.logger.info("Hook6: Output water molecules in Yaplot format.")
    lattice.logger.info("  Total number of atoms: {0}".format(
        len(lattice.atoms)))
    # prepare the reverse dict
    waters = defaultdict(dict)
    for atom in lattice.atoms:
        resno, resname, atomname, position, order = atom
        if "O" in atomname:
            waters[order]["O"] = position
        elif "H" in atomname:
            if "H0" not in waters[order]:
                waters[order]["H0"] = position
            else:
                waters[order]["H1"] = position
    s = ""
    s += yp.Color(3)
    for order, water in waters.items():
        O = water["O"]
        H0 = water["H0"]
        H1 = water["H1"]
        s += yp.Layer(4)
        s += yp.Color(3)
        s += yp.Size(0.03)
        s += yp.Circle(O)
        s += yp.Line(O, H0)
        s += yp.Line(O, H1)
        s += yp.Size(lattice.yaplot_size_H)
        s += yp.Circle(H0)
        s += yp.Circle(H1)
        s += yp.Color(2)
        s += yp.Layer(1)
        s += yp.Text(O, "{0}".format(order))
    s += yp.Layer(3)
    s += yp.Color(4)
    s += yp.ArrowType(1)
    s += yp.Size(0.03)
    for i, j in lattice.spacegraph.edges(data=False):
        if i in waters and j in waters:  # edge may connect to the dopant
            O = waters[j]["O"]
            H0 = waters[i]["H0"]
            H1 = waters[i]["H1"]
            d0 = H0 - O
            d1 = H1 - O
            rr0 = np.dot(d0, d0)
            rr1 = np.dot(d1, d1)
            if rr0 < rr1 and rr0 < 0.245**2:
                s += yp.Arrow(H0, O)
            if rr1 < rr0 and rr1 < 0.245**2:
                s += yp.Arrow(H1, O)
    print(s, end="")
    nwateratoms = len(lattice.atoms)
    lattice.logger.info("Hook6: end.")
Пример #3
0
def to_yaplot(cellmat, rpos, anions, cations, G, cation="N", anion="F"):
    """
    cellmat: セル行列(後置記法)
    rpos:    分子のセル内相対位置
    anions:  アニオン番号
    cations: カチオン番号
    G:       水素結合ネットワーク
    """
    # 水分子の原子位置
    water = tip4picesites()

    s = ""
    for mol in G:
        if mol not in anions and mol not in cations:
            # genuine water molecule.
            rO = rpos[mol]
            H1, H2 = G[mol]
            rH1 = rpos[H1] - rO
            rH1 -= np.floor(rH1 + 0.5)
            rH2 = rpos[H2] - rO
            rH2 -= np.floor(rH2 + 0.5)
            # 実座標 (angstrom)
            pO = rO @ cellmat
            pH1 = rH1 @ cellmat
            pH2 = rH2 @ cellmat
            ey = pH1 - pH2
            ez = pH1 + pH2
            ex = np.cross(ey, ez)
            # 分子内座標方向の単位ベクトル
            ex /= np.linalg.norm(ex)
            ey /= np.linalg.norm(ey)
            ez /= np.linalg.norm(ez)
            # 回転行列
            R = np.array([ex, ey, ez])
            # 水分子の原子位置
            intra = water @ R + pO
            s += draw_water(intra)
    s += yp.Layer(3)
    s += yp.Size(0.5)
    s += yp.Color(6)
    for mol in G:
        if mol in anions:
            pos = rpos[mol] @ cellmat
            s += yp.Circle(pos)
    s += yp.Size(0.3)
    s += yp.Color(7)
    for mol in G:
        if mol in cations:
            pos = rpos[mol] @ cellmat
            s += yp.Circle(pos)
    s += yp.NewPage()
    return s
Пример #4
0
def hook7(lattice):
    global nwateratoms
    lattice.logger.info("Hook7: Output water molecules in Yaplot format.")
    lattice.logger.info("  Total number of atoms: {0}".format(
        len(lattice.atoms)))
    gatoms = lattice.atoms[nwateratoms:]
    palettes = dict()
    s = ""
    s += yp.Layer(4)
    s += yp.ArrowType(1)
    H = []
    O = ""
    for atom in gatoms:
        resno, resname, atomname, position, order = atom
        if atomname in palettes:
            pal = palettes[atomname]
        else:
            pal = 4 + len(palettes)
            palettes[atomname] = pal
        s += yp.Color(pal)
        s += yp.Size(0.04)
        s += yp.Circle(position)
    s = '#' + "\n#".join(lattice.doc) + "\n" + s
    print(s)
    lattice.logger.info("Hook7: end.")
Пример #5
0
def draw_water(water, povray=False):
    s = ""
    if povray:
        s += pov.Sphere(water[0], r="RH", material="MATH")
        s += pov.Sphere(water[1], r="RH", material="MATH")
        s += pov.Sphere(water[2], r="RO", material="MATO")
        s += pov.Cylinder(water[0], water[2], r="ROH", material="MATOH")
        s += pov.Cylinder(water[1], water[2], r="ROH", material="MATOH")
    else:
        s += yp.Layer(1)
        s += yp.Color(5)
        s += yp.Size(0.2)
        s += yp.Circle(water[0])
        s += yp.Circle(water[1])
        s += yp.Color(4)
        s += yp.Size(0.4)
        s += yp.Circle(water[2])
        s += yp.Color(2)
        d0 = water[0] - water[2]
        L0 = np.linalg.norm(d0)
        s += yp.Line(water[2] + d0 / L0 * 0.4, water[0] - d0 / L0 * 0.2)
        d1 = water[1] - water[2]
        L1 = np.linalg.norm(d1)
        s += yp.Line(water[2] + d1 / L1 * 0.4, water[1] - d1 / L1 * 0.2)
        # draw a tetrahedron
        y = water[1] - water[0]
        z = (water[1] + water[0]) / 2 - water[2]
        x = np.cross(y, z)
        x /= np.linalg.norm(x)
        y /= np.linalg.norm(y)
        z /= np.linalg.norm(z)
        com = (water[1] + water[0] + water[2] * 16) / 18
        R = 2.76 / 2
        a = y * (2 / 3)**0.5 + z * (1 / 3)**0.5
        b = -y * (2 / 3)**0.5 + z * (1 / 3)**0.5
        c = x * (2 / 3)**0.5 - z * (1 / 3)**0.5
        d = -x * (2 / 3)**0.5 - z * (1 / 3)**0.5
        s += yp.Layer(2)
        for e, f in it.combinations((a, b, c, d), 2):
            s += yp.Line(com + e * R, com + f * R)
    return s
Пример #6
0
def main():
    import sys
    groname, twiname = sys.argv[1:3]

    with open(twiname) as twifile:
        with open(groname) as grofile:
            while True:
                if groname[-4:] == ".pdb":
                    gr = pdb.PDB(grofile, "O", "H", resname="WAT")
                else:
                    # assume it is gromacs
                    gr = gro.Gromacs(grofile, "Ow", "Hw", "Mw")
                btw = btwc.load_BTWC(twifile)
                if btw is None or gr is None:
                    break
                celli = np.linalg.inv(gr.cell)
                # relative coord
                rs = np.array([np.dot(x, celli) for x in gr.solutes])
                ro = np.array([np.dot(x, celli) for x in gr.waters])
                print(len(rs))
                print(len(ro))
                grid = pl.determine_grid(gr.cell, 0.245)
                shell1 = np.vstack(
                    pl.pairs_fine_hetero(rs,
                                         ro,
                                         0.4,
                                         gr.cell,
                                         grid,
                                         distance=False))
                # some solute atoms are isolated from water.
                shell1s = set(shell1[:, 0])
                shell1w = set(shell1[:, 1])
                #show all bonds in yaplot
                s = ""
                for i in range(-10, 0):
                    s += yap.SetPalette(i + 10 + 3, 255 * (-i) // 10, 0, 0)
                for i in range(11):
                    s += yap.SetPalette(i + 10 + 3, 0, 0, 255 * i // 10)
                for b in btw:
                    i, j = b[0]
                    if i in shell1w or j in shell1w:
                        s += yap.Layer(1)
                    else:
                        s += yap.Layer(2)
                    r = abs(b[2])
                    sine = b[2].imag
                    s += yap.Size(r)
                    s += yap.Color(int(sine * 10) + 10 + 3)
                    s += yap.Circle(b[1])
                print(s)
Пример #7
0
def hook2(lattice):
    global nwateratoms
    if lattice.yaplot_size_H > 0:
        return
    lattice.logger.info(
        "Hook2: Output CoM of water molecules in Yaplot format.")
    # prepare the reverse dict
    waters = defaultdict(dict)
    pos = lattice.reppositions @ lattice.repcell.mat
    s = ""
    for p in pos:
        s += yp.Layer(4)
        s += yp.Color(3)
        s += yp.Size(0.03)
        s += yp.Circle(p)
    print(s, end="")
    lattice.logger.info("Hook2: end.")
    return True
Пример #8
0
def main():
    gro = open(sys.argv[1])
    box, atoms = LoadGRO(gro)
    ratoms = atoms/box
    cellmat = np.diag(box)
    page1 = ""
    page2 = ""
    page3 = ""
    page4 = ""
    page1 += yp.Size(0.05)
    grid = None
    while True:
        line = sys.stdin.readline() #expect *.smatch result of slide-matcher2
        if len(line) == 0:
            break
        cols = line.split()
        if len(cols)<7:
            break # broken line; maybe end of the file.
        i,j = [int(x) for x in cols[:2]]
        rad, dx,dy,dz, rmsd = [float(x) for x in cols[2:]]
        if grid is None:
            grid = pairlist.determine_grid(cellmat, rad)
            lastrad = rad
            p,q,r = pairlist.pairs_fine(ratoms, rad, cellmat, grid, distance=True, raw=True)
            g = nx.Graph()
            for k,pq in enumerate(zip(p,q)):
                p,q = pq
                g.add_edge(p,q,length=r[k])
        else:
            assert lastrad == rad
        d = np.array([dx,dy,dz])
        if rmsd < 0.09: # 0.09 for hyper ice T
            # page 1: displacement vectors
            page1 += yp.Line(atoms[i], atoms[i]+d)
            page1 += yp.Circle(atoms[j])
            # pages 2: displacement vectors (centered)
            page2 += yp.Size(0.05)
            page2 += yp.Line(np.zeros(3), d)
            page2 += yp.Circle(d)
            page2 += yp.Text(d, "{0} {1}".format(i,j))
            # page 3..: matching
            s = ""
            s += yp.Size(0.05)
            s += yp.Layer(1)
            s += yp.Color(3)
            for ni in g[i]:
                s += yp.Circle(atoms[ni])
            s += yp.Layer(2)
            s += yp.Color(4)
            for nj in g[j]:
                s += yp.Circle(atoms[nj]-atoms[j]+atoms[i])
            page3 += s
            s = ""
            s += yp.Size(0.05)
            s += yp.Layer(1)
            s += yp.Color(3)
            for ni in g[i]:
                s += yp.Circle(atoms[ni]-atoms[i])
            s += yp.Layer(2)
            s += yp.Color(4)
            for nj in g[j]:
                s += yp.Circle(atoms[nj]-atoms[j])
            page4 += s
            page4 += yp.NewPage()

    print(page1)
    print(page2)
    print(page3)
    print(page4)