Beispiel #1
0
def deb_energy(images, debframe=[], i=6, j=8, show=False):
    ir = IRFF_NP(atoms=images[0], libfile='ffield.json', nn=True)
    ir.calculate_Delta(images[0])

    Eb, Ea, e = [], [], []
    Ehb, Eo, Ev, Eu, El = [], [], [], [], []
    Etor, Ef, Ep, Et = [], [], [], []

    for i_, atoms in enumerate(images):
        ir.calculate(images[i_])
        # print('%d Energies: ' %i_,'%12.4f ' %ir.E, 'Ebd: %8.4f' %ir.ebond[0][1],'Ebd: %8.4f' %ir.ebond[2][3] )
        Eb.append(ir.Ebond)
        Ea.append(ir.Eang)
        Eo.append(ir.Eover)
        Ev.append(ir.Evdw)
        Eu.append(ir.Eunder)
        El.append(ir.Elone)
        Ep.append(ir.Epen)
        Et.append(ir.Etcon)
        Ef.append(ir.Efcon)
        Etor.append(ir.Etor)
        Ehb.append(ir.Ehb)
        e.append(ir.E)

    plot(e, Eb, Eu, Eo, El, Ea, Et, Ep, Etor, Ef, Ev, Ehb, show=show)
    return e
Beispiel #2
0
def plot_bondorder():
    #atoms = structure('HMX')
    atoms = read('poscar.gen', index=-1)
    # atoms = atoms*[2,2,2]
    # view(atoms)

    # atoms = read('md.traj',index=-1)
    atom_name = atoms.get_chemical_symbols()
    ir = IRFF_NP(atoms=atoms, libfile='ffield.json', rcut=None, nn=True)
    ir.calculate_Delta(atoms)

    fig = plt.figure()
    # set figure information
    # plt.set_title("Bond-Order")
    plt.xlabel("Atom ID")
    plt.ylabel("Atom ID")

    plt.imshow(ir.bop, cmap='jet')  # atom conection matrix
    plt.colorbar()
    # plt.grid()
    plt.savefig('bop.eps')
    plt.close()

    fig = plt.figure()
    plt.xlabel("Atom ID")
    plt.ylabel("Atom ID")
    plt.imshow(ir.bo0, cmap='jet')  # atom conection matrix
    plt.colorbar()
    # plt.grid()
    plt.savefig('bo.eps')
    plt.close()
Beispiel #3
0
def deb_vdw(images, i=0, j=1, show=False):
    ir = IRFF_NP(atoms=images[0], libfile='ffield.json', nn=True)
    ir.calculate_Delta(images[0])

    Eb, Ea, e = [], [], []
    Ehb, Eo, Ev, Eu, El = [], [], [], [], []
    Etor, Ef, Ep, Et = [], [], [], []

    for i_, atoms in enumerate(images):
        ir.calculate(images[i_])
        # print('%d Energies: ' %i_,'%12.4f ' %ir.E, 'Ebd: %8.4f' %ir.ebond[0][1],'Ebd: %8.4f' %ir.ebond[2][3] )
        Eb.append(ir.Ebond)
        Ea.append(ir.Eang)
        Eo.append(ir.Eover)
        Ev.append(ir.Evdw)
        Eu.append(ir.Eunder)
        El.append(ir.Elone)
        Ep.append(ir.Epen)
        Et.append(ir.Etcon)
        Ef.append(ir.Efcon)
        Etor.append(ir.Etor)
        Ehb.append(ir.Ehb)
        e.append(ir.E)

    emin_ = np.min(Eb)
    eb = np.array(Eb) - emin_  # )/emin_
    vmin_ = np.min(Ev)
    ev = np.array(EV) - vmin_  # )/emin_

    plt.figure(figsize=figsize)
    # plt.plot(bopsi,alpha=0.8,linewidth=2,linestyle=':',color='k',label=r'$BO_p^{\sigma}$')
    # plt.plot(boppi,alpha=0.8,linewidth=2,linestyle='-.',color='k',label=r'$BO_p^{\pi}$')
    # plt.plot(boppp,alpha=0.8,linewidth=2,linestyle='--',color='k',label=r'$BO_p^{\pi\pi}$')
    # plt.plot(bo0,alpha=0.8,linewidth=2,linestyle='-',color='g',label=r'$BO^{t=0}$')

    plt.plot(ev,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='y',
             label=r'$E_{vdw}$')
    plt.plot(eb,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='r',
             label=r'$E_{bond}$')

    plt.legend(loc='best', edgecolor='yellowgreen')
    plt.savefig('deb_bo.pdf')
    if show: plt.show()
    plt.close()
    return eb, ev
Beispiel #4
0
def eover(i=0, j=1, ffield='ffield.json', nn='T', traj='md.traj'):
    # atoms = read(traj)
    # ao = AtomDance(atoms)
    # images = ao.stretch([[i,j]],nbin=50,traj=False)
    images = Trajectory(traj)
    atoms = images[0]

    nn_ = True if nn == 'T' else False
    ir = IRFF_NP(atoms=atoms, libfile=ffield, rcut=None, nn=nn_)

    ir.calculate_Delta(atoms)
    natom = ir.natom

    r_,eb,bosi,bop_si,bop,bop_pi,bop_pp,bo = [],[],[],[],[],[],[],[]
    eba, eo, dlpi, dlpj, ev, boe = [], [], [], [], [], []
    esi, epi, epp = [], [], []
    Di, Dj = [], []
    Dpi = []

    for atoms in images:
        positions = atoms.positions
        v = positions[j] - positions[i]
        r = np.sqrt(np.sum(np.square(v)))

        ir.calculate(atoms)
        r_.append(ir.r[i][j])
        eb.append(ir.ebond[i][j])
        eba.append(ir.ebond[i][j] + ir.eover[i] + ir.Evdw)
        ev.append(ir.Evdw)
        eo.append(ir.Eover)
        # print(ir.so[j],ir.eover[j])

        dlpi.append(ir.Delta_lpcorr[i])
        dlpj.append(ir.Delta_lpcorr[j])
        Di.append(ir.Delta[i])
        Dj.append(ir.Delta[j])
        Dpi.append(ir.Dpil[j])

    fig, ax = plt.subplots()
    ax.plot(eo, label=r'$E_{over}$', color='r', linewidth=2, linestyle='-')

    #     fig, ax = plt.subplots(2,1,2)
    #     plt.plot(r_,dlpj,label=r'$\Delta_{lp}$(%s%d)' %(ir.atom_name[j],j),
    #              color='b', linewidth=2, linestyle='-') # Dpil
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.savefig('Eover.pdf')
    # plt.show()
    plt.close()
Beispiel #5
0
def deb_eang(images, ang=[0, 1, 2], figsize=(8, 6), show=False, print_=False):
    i, j, k = ang
    ang_ = [k, j, i]
    a = 0
    found = False
    eang, ecoa, epen = [], [], []

    ir = IRFF_NP(atoms=images[0], libfile='ffield.json', nn=True)
    ir.calculate_Delta(images[0])

    for na, angle in enumerate(ir.angs):
        i_, j_, k_ = angle
        if (i_ == i and j_ == j and k_ == k) or (i_ == k and j_ == j
                                                 and k_ == i):
            a = na
            found = True

    if not found:
        print('Error: no angle found for', ang, angle)

    for i_, atoms in enumerate(images):
        ir.calculate(atoms)

        eang.append(ir.Eang)
        ecoa.append(ir.Etcon)
        epen.append(ir.Epen)
        if print_:
            # for a,angle in enumerate(ir.angs):
            #i_,j_,k_ = angle
            print(
                '{:3d}  {:6.4f}  {:6.4f} Dpi: {:6.4f} pbo: {:6.4f} N: {:6.4f} SBO3: {:6.4f}'
                .format(i_, ir.thet0[a], ir.theta[a], ir.sbo[a], ir.pbo[a],
                        ir.nlp[j], ir.SBO3[a]))  # self.thet0-self.theta

    plt.figure(figsize=figsize)
    plt.plot(eang,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='r',
             label=r'$E_{ang}$')  # ($-E_{ang}/{:4.2f}$)'.format(ang_m))
    # plt.plot(ecoa,alpha=0.8,linewidth=2,linestyle='-',color='indigo',label=r'$E_{coa}$') # ($E_{coa}/%4.2f$)' %emx)
    # plt.plot(epen,alpha=0.8,linewidth=2,linestyle='-',color='b',label=r'$E_{pen}$') # ($E_{pen}/%4.2f$)' %eox)
    plt.legend(loc='best', edgecolor='yellowgreen')
    plt.savefig('deb_ang.pdf')
    if show: plt.show()
    plt.close()
Beispiel #6
0
class AtomDance(object):
    def __init__(self,
                 atoms=None,
                 poscar=None,
                 nn=True,
                 rtole=0.5,
                 bondTole=1.25,
                 botol=0.0):
        self.rtole = rtole
        self.bondTole = bondTole
        self.botol = botol
        self.BondDistrubed = []
        if atoms is None:
            if poscar is None:
                atoms = read('poscar.gen')
            else:
                atoms = read(poscar)

        self.ir = IRFF_NP(atoms=atoms, libfile='ffield.json', rcut=None, nn=nn)
        self.natom = self.ir.natom
        self.atom_name = self.ir.atom_name
        spec = self.ir.spec
        self.mass = atoms.get_masses()

        label_dic = {}
        for sp in self.atom_name:
            if sp in label_dic:
                label_dic[sp] += 1
            else:
                label_dic[sp] = 1
        self.label = ''
        for sp in spec:
            self.label += sp + str(label_dic[sp])

        self.ir.calculate_Delta(atoms)
        self.InitBonds = getBonds(self.natom,
                                  self.ir.r,
                                  self.bondTole * self.ir.re,
                                  self.ir.bo0,
                                  botol=self.botol)

        self.neighbors = getNeighbor(self.natom,
                                     self.ir.r,
                                     self.bondTole * self.ir.re,
                                     self.ir.bo0,
                                     botol=self.botol)

    def bond_momenta_bigest(self, atoms):
        ratio = []
        s = []
        for bd in self.InitBonds:
            i, j = bd
            ratio_ = self.ir.r[i][j] / self.ir.re[i][j]
            s_ = ratio_ - 1.0
            s.append(s_)
            ratio.append(abs(s_))

        m_ = np.argmax(ratio)
        i, j = self.InitBonds[m_]
        s_ = s[m_]
        if s_ >= 0.0:
            sign = 1.0
        else:
            sign = -1.0
        atoms = self.set_bond_momenta(i, j, atoms, sign=sign)
        return atoms

    def bond_momenta(self, atoms):
        ratio = []
        for bd in self.InitBonds:
            i, j = bd
            if bd not in self.BondDistrubed:
                s_ = self.ir.r[i][j] / self.ir.re[i][j] - 1.0
                if s_ >= 0.0:
                    sign = 1.0
                else:
                    sign = -1.0
                self.BondDistrubed.append(bd)
                atoms = self.set_bond_momenta(i, j, atoms, sign=sign)
                return atoms, True
        return atoms, False

    def set_bond_momenta(self, i, j, atoms, sign=1.0):
        ha = int(0.5 * self.natom)
        # x     = atoms.get_positions()
        v = np.zeros([self.natom, 3])

        group_j = []
        group_j, ring = getAtomsToMove(i, j, j, group_j, self.neighbors)
        jg = len(group_j)

        group_i = []
        group_i, ring = getAtomsToMove(j, i, i, group_i, self.neighbors)
        ig = len(group_i)

        if ring:
            group_i = [i]
            group_j = [j]

        vij = self.ir.vr[j][i] / self.ir.r[i][j]
        massi = 0.0
        massj = 0.0

        for a in group_i:
            massi += self.mass[a]
        for a in group_j:
            massj += self.mass[a]

        vi = 1.0 / massi
        vj = 1.0 / massj

        for a in group_i:
            v[a] = sign * vi * vij

        for a in group_j:
            v[a] = -sign * vj * vij
        atoms.set_velocities(v)
        return atoms

    def check_bond(self, atoms=None, mdtraj=None, bondTole=1.3):
        if atoms is None:
            atoms = self.ir.atoms
        if not bondTole is None:
            self.bondTole = bondTole
        self.ir.calculate_Delta(atoms, updateP=True)
        bkbd = None
        bB_ = 0

        bondBroken = False
        bondTole_ = self.bondTole - 0.015
        bonds = getBonds(self.natom,
                         self.ir.r,
                         bondTole_ * self.ir.re,
                         self.ir.bo0,
                         botol=self.botol * 0.5)

        if len(bonds) == len(self.InitBonds):
            for bd in self.InitBonds:
                bd_ = (bd[1], bd[0])
                if (bd not in bonds) and (bd_ not in bonds):
                    bkbd = bd
                    bondBroken = True
                    break
        else:
            bondBroken = True
        if bondBroken:
            bB_ += 1

        bondBroken = False
        bondTole_ = self.bondTole
        bonds = getBonds(self.natom,
                         self.ir.r,
                         bondTole_ * self.ir.re,
                         self.ir.bo0,
                         botol=self.botol)
        if len(bonds) == len(self.InitBonds):
            for bd in self.InitBonds:
                bd_ = (bd[1], bd[0])
                if (bd not in bonds) and (bd_ not in bonds):
                    bondBroken = True
                    break
        else:
            bondBroken = True
        if bondBroken:
            bB_ += 1
        return bB_, bkbd

    def check(self, wcheck=2, i=0, atoms=None, rtole=None):
        if atoms is None:
            atoms = self.ir.atoms
        if not rtole is None:
            self.rtole = rtole

        self.ir.calculate_Delta(atoms, updateP=True)

        fc = open('check.log', 'w')
        if i % wcheck == 0:
            atoms = self.checkLoneAtoms(atoms, fc)
        else:
            atoms = self.checkLoneAtom(atoms, fc)

        atoms = self.checkClosedAtom(atoms, fc)
        fc.close()
        return atoms

    def checkLoneAtom(self, atoms, fc):
        for i in range(self.natom):
            if self.ir.Delta[i] <= self.ir.atol:
                print('- find an lone atom', i, self.atom_name[i], file=fc)
                sid = np.argsort(self.ir.r[i])
                for j in sid:
                    if self.ir.r[i][j] > 0.0001:
                        print('  move lone atom to nearest neighbor: %d' % j,
                              file=fc)
                        vr = self.ir.vr[i][j]
                        u = vr / np.sqrt(np.sum(np.square(vr)))
                        atoms.positions[i] = atoms.positions[
                            j] + u * 0.64 * self.ir.r_cuta[i][j]
                        break
                self.ir.calculate_Delta(atoms)
        return atoms

    def checkLoneAtoms(self, atoms, fc):
        for i in range(self.natom):
            if self.ir.Delta[i] <= self.ir.atol:
                print('- find an lone atom', i, self.atom_name[i], file=fc)
                mid = np.argmin(self.ir.ND)

                if mid == i:
                    continue

                print('- find the most atractive atom:', mid, file=fc)
                print('\n- neighors of atom %d %s:' % (i, self.atom_name[i]),
                      end='',
                      file=fc)
                neighs = []
                for j, bo in enumerate(self.ir.bo0[mid]):
                    if bo > self.ir.botol:
                        neighs.append(j)
                        print(j, self.atom_name[j], end='', file=fc)
                print(' ', file=fc)

                if len(neighs) == 0:
                    vr = self.ir.vr[mid][i]
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    atoms.positions[i] = atoms.positions[
                        mid] + u * 0.64 * self.ir.r_cuta[i][mid]
                elif len(neighs) == 1:
                    j = neighs[0]
                    vr = self.ir.vr[mid][j]
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    atoms.positions[i] = atoms.positions[
                        mid] + u * 0.64 * self.ir.r_cuta[i][mid]
                elif len(neighs) == 2:
                    i_, j_ = neighs
                    xj = atoms.positions[mid]
                    xi = 0.5 * (atoms.positions[i_] + atoms.positions[j_])
                    vr = xj - xi
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    vij = atoms.positions[j_] - atoms.positions[i_]
                    rij = np.sqrt(np.sum(np.square(vij)))
                    r_ = np.dot(vij, u)
                    if r_ != rij:
                        atoms.positions[i] = atoms.positions[
                            mid] + u * 0.64 * self.ir.r_cuta[i][mid]
                elif len(neighs) == 3:
                    i_, j_, k_ = neighs
                    vi = atoms.positions[i_] - atoms.positions[j_]
                    vj = atoms.positions[i_] - atoms.positions[k_]
                    # cross product
                    vr = np.cross(vi, vj)
                    c = (atoms.positions[i_] + atoms.positions[j_] +
                         atoms.positions[k_]) / 3
                    v = atoms.positions[mid] - c
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    # dot product
                    dot = np.dot(v, u)
                    if dot <= 0:
                        u = -u
                    atoms.positions[i] = atoms.positions[
                        mid] + u * 0.64 * self.ir.r_cuta[i][mid]

                self.ir.calculate_Delta(atoms)
        return atoms

    def checkClosedAtom(self, atoms, fc):
        self.ir.calculate_Delta(atoms)
        neighbors = getNeighbor(self.natom, self.ir.r, self.ir.r_cuta,
                                self.ir.bo0)
        for i in range(self.natom - 1):
            for j in range(i + 1, self.natom):
                if self.ir.r[i][j] < self.rtole * self.ir.r_cuta[i][j]:
                    print('- atoms %d and %d too closed' % (i, j), file=fc)

                    moveDirection = self.ir.vr[j][i] / self.ir.r[i][j]
                    moveD = self.ir.r_cuta[i][j] * (self.rtole +
                                                    0.01) - self.ir.r[i][j]
                    moveV = moveD * moveDirection

                    ToBeMove = []
                    ToBeMove, ring = getAtomsToMove(i, j, j, ToBeMove,
                                                    neighbors)
                    print('  atoms to to be moved:', ToBeMove, file=fc)
                    for m in ToBeMove:
                        newPos = atoms.positions[m] + moveV
                        r = np.sqrt(
                            np.sum(np.square(newPos - atoms.positions[i])))
                        if r > self.ir.r[i][m]:
                            atoms.positions[m] = newPos
                    self.ir.calculate_Delta(atoms)
                    neighbors = getNeighbor(self.natom, self.ir.r,
                                            self.ir.r_cuta, self.ir.bo0)
        return atoms

    def bend(self, ang=None, rang=20.0, nbin=10, scale=1.2, wtraj=False):
        i, j, k = ang
        axis = [i, k]
        images = self.rotate(atms=[i, k],
                             axis=axis,
                             o=j,
                             rang=rang,
                             nbin=nbin,
                             wtraj=wtraj,
                             scale=scale)
        return images

    def bend_axis(self,
                  axis=None,
                  group=None,
                  rang=20,
                  nbin=30,
                  scale=1.2,
                  wtraj=False):
        images = self.rotate(atms=group,
                             axis=axis,
                             o=axis[0],
                             rang=rang,
                             nbin=nbin,
                             wtraj=wtraj,
                             scale=scale)
        return images

    def swing_group(self,
                    ang=None,
                    group=None,
                    rang=20,
                    nbin=30,
                    scale=1.2,
                    wtraj=False):
        i, j, k = ang
        atoms = self.ir.atoms
        self.ir.calculate_Delta(atoms)

        vij = atoms.positions[i] - atoms.positions[j]
        vjk = atoms.positions[k] - atoms.positions[j]
        r = self.ir.r[j][k]
        ujk = vjk / r
        ui = vij / self.ir.r[i][j]
        uk = np.cross(ui, ujk)
        rk = np.sqrt(np.sum(uk * uk))

        if rk < 0.0000001:
            uk = np.array([1.0, 0.0, 0.0])
        else:
            uk = uk / rk
        images = self.rotate(atms=group,
                             axis_vector=uk,
                             o=j,
                             rang=rang,
                             nbin=nbin,
                             wtraj=wtraj,
                             scale=scale)
        return images

    def rotate(self,
               atms=None,
               axis=None,
               axis_vector=None,
               o=None,
               rang=20.0,
               nbin=10,
               wtraj=False,
               scale=1.2):
        da = 2.0 * rang / nbin
        atoms = self.ir.atoms
        self.ir.calculate_Delta(atoms)
        neighbors = getNeighbor(self.natom, self.ir.r, scale * self.ir.re,
                                self.ir.bo0)

        images = []
        if wtraj: his = TrajectoryWriter('rotate.traj', mode='a')

        if axis_vector is None:
            i, j = axis
            vaxis = atoms.positions[j] - atoms.positions[i]
            uk = vaxis / self.ir.r[i][j]
        else:
            uk = axis_vector

        a_ = -rang
        while a_ < rang:
            atoms_ = atoms.copy()
            for atomk in atms:
                vo = atoms.positions[atomk] - atoms.positions[o]
                r_ = np.dot(vo, uk)

                o_ = atoms.positions[o] + r_ * uk
                vi = atoms.positions[atomk] - o_

                r = np.sqrt(np.sum(np.square(vi)))
                ui = vi / r
                uj = np.cross(uk, ui)

                a = a_ * 3.14159 / 180.0
                p = r * np.cos(a) * ui + r * np.sin(a) * uj

                atoms_.positions[atomk] = o_ + p
                self.ir.calculate(atoms_)

                calc = SinglePointCalculator(atoms_, energy=self.ir.E)
                atoms_.set_calculator(calc)

            images.append(atoms_)
            if wtraj: his.write(atoms=atoms_)
            a_ += da
        return images

    def swing(self, ang, st=60.0, ed=180.0, nbin=50, scale=1.2, wtraj=False):
        da = (ed - st) / nbin
        i, j, k = ang
        atoms = self.ir.atoms
        self.ir.calculate_Delta(atoms)
        neighbors = getNeighbor(self.natom, self.ir.r, scale * self.ir.re,
                                self.ir.bo0)
        images = []
        if wtraj: his = TrajectoryWriter('swing.traj', mode='w')

        vij = atoms.positions[i] - atoms.positions[j]
        vjk = atoms.positions[k] - atoms.positions[j]
        r = self.ir.r[j][k]
        ujk = vjk / r
        ui = vij / self.ir.r[i][j]
        uk = np.cross(ui, ujk)
        rk = np.sqrt(np.sum(uk * uk))

        if rk < 0.0000001:
            uk = np.array([1.0, 0.0, 0.0])
        else:
            uk = uk / rk

        uj = np.cross(uk, ui)
        a_ = st

        while a_ < ed:
            atoms_ = atoms.copy()
            a = a_ * 3.14159 / 180.0
            p = r * np.cos(a) * ui + r * np.sin(a) * uj
            atoms_.positions[k] = atoms_.positions[j] + p
            self.ir.calculate(atoms_)

            calc = SinglePointCalculator(atoms_, energy=self.ir.E)
            atoms_.set_calculator(calc)

            images.append(atoms_)
            if wtraj: his.write(atoms=atoms_)
            a_ += da

        if wtraj: his.close()
        return images

    def stretch(self,
                pair,
                atoms=None,
                nbin=20,
                st=0.7,
                ed=1.3,
                scale=1.25,
                traj=None,
                ToBeMoved=None):
        if atoms is None:
            atoms = self.ir.atoms
        self.ir.calculate_Delta(atoms)
        neighbors = getNeighbor(self.natom, self.ir.r, scale * self.ir.re,
                                self.ir.bo0)
        images = []

        if not traj is None: his = TrajectoryWriter(traj, mode='w')
        #for pair in pairs:
        i, j = pair
        if ToBeMoved is None:
            ToBeMove = []
            ToBeMove, ring = getAtomsToMove(i, j, j, ToBeMove, neighbors)
        else:
            ToBeMove = ToBeMoved

        bin_ = (self.ir.re[i][j] * ed - self.ir.re[i][j] * st) / nbin
        moveDirection = self.ir.vr[j][i] / self.ir.r[i][j]

        if ring:
            return None

        for n in range(nbin):
            atoms_ = atoms.copy()
            moveV = atoms.positions[i] + moveDirection * (
                self.ir.re[i][j] * st + bin_ * n) - atoms.positions[j]
            # print(self.ir.re[i][j]*self.rtole+bin_*n)
            for m in ToBeMove:
                # sPos   = atoms.positions[i] + self.ir.re[i][m]*self.rtole*moveDirection
                newPos = atoms.positions[m] + moveV
                r = np.sqrt(np.sum(np.square(newPos - atoms.positions[i])))
                atoms_.positions[m] = newPos

            self.ir.calculate(atoms_)
            i_ = np.where(
                np.logical_and(
                    self.ir.r < self.ir.re[i][j] * self.rtole - bin_,
                    self.ir.r > 0.0001))
            n = len(i_[0])
            try:
                assert n == 0, 'Atoms too closed!'
            except:
                print('Atoms too closed.')
                break

            calc = SinglePointCalculator(atoms_, energy=self.ir.E)
            atoms_.set_calculator(calc)
            images.append(atoms_)
            if not traj is None: his.write(atoms=atoms_)

        if not traj is None: his.close()
        return images

    def close(self):
        self.ir = None
        self.atom_name = None
Beispiel #7
0
def MessagePassing(atoms,
                   color={
                       'C': 'dimgray',
                       'H': 'silver',
                       'O': 'crimson',
                       'N': 'dodgerblue'
                   },
                   size={
                       'C': 320,
                       'H': 90,
                       'O': 180,
                       'N': 320
                   },
                   bondColor='darkgoldenrod',
                   boxColor='steelblue',
                   bondWidth=2,
                   elev=45,
                   azim=45,
                   Axis=True,
                   Box=True,
                   t=0,
                   text='edge',
                   labelnode=False):
    ''' avilable colors: ghostwhite whitesmoke olive '''
    positions = atoms.get_positions()
    sym = atoms.get_chemical_symbols()

    ir = IRFF_NP(atoms=atoms, libfile='ffield.json', rcut=None, nn=True)
    ir.calculate_Delta(atoms)

    # plot scatter points
    fig, ax = plt.subplots()

    #     ax.set_xlim([0,5])
    #     ax.set_ylim([0,5])
    x_, y_, z_ = [], [], []
    #     circ=plt.Circle((1.5, 0.5),radius=0.2,color=(58/255,94/255,148/255))
    #     ax.add_patch(circ)
    for i, atom in enumerate(atoms):
        x_.append(atom.x)
        y_.append(atom.y)
        z_.append(atom.z)
        plt.scatter(atom.y,
                    atom.z,
                    c=color[sym[i]],
                    marker='o',
                    s=size[sym[i]],
                    label=sym[i],
                    alpha=1)
        if text == 'node':
            plt.text(atom.y - 0.15,
                     atom.z,
                     r'$%3.2f$' % ir.Delta[i],
                     fontsize=20)
        else:
            if labelnode:
                plt.text(atom.y - 0.11,
                         atom.z,
                         r'$%s%d$' % (ir.atom_name[i], i),
                         fontsize=20)
    xmin, ymin = np.min(atoms.positions[:, 1]), np.min(atoms.positions[:, 2])
    yl, yh = ax.get_ylim()
    yr = yh - yl
    xl, xh = ax.get_xlim()
    xr = xh - xl

    for i in range(ir.natom - 1):
        for j in range(i + 1, ir.natom):
            if ir.bo0[i][j] > 0.05:
                x = [atoms.positions[i][0], atoms.positions[j][0]]
                y = [atoms.positions[i][1], atoms.positions[j][1]]
                z = [atoms.positions[i][2], atoms.positions[j][2]]
                # plt.plot(y,z,c=bondColor,linewidth=5,alpha=0.8)
                line = mlines.Line2D(y,
                                     z,
                                     lw=bondWidth * ir.bop[i][j],
                                     ls='-',
                                     alpha=1,
                                     color=bondColor)
                line.set_zorder(0)
                ax.add_line(line)
                if text == 'edge':
                    # if ir.atom_name[i]=='C' and ir.atom_name[j]=='C':
                    #    plt.text(0.5*(y[0]+y[1])-0.05*xr,0.5*(z[0]+z[1]),
                    #             r'$BO=%3.2f$' %ir.H[t][i][j],
                    #             fontsize=16)
                    #    eb = ir.ebond[i][j]
                    #    si = ir.Hsi[t][i][j]
                    #    pi = ir.Hpi[t][i][j]
                    #    pp = ir.Hpp[t][i][j]
                    #    plt.text(0.5*(y[0]+y[1])-0.05*xr,0.5*(z[0]+z[1])+0.3*yr,
                    #             r'$BO^{\sigma}=%3.2f$' %si,fontsize=16)
                    #    plt.text(0.5*(y[0]+y[1])-0.05*xr,0.5*(z[0]+z[1])+0.2*yr,
                    #             r'$BO^{\pi}=%3.2f$' %pi,fontsize=16)
                    #    plt.text(0.5*(y[0]+y[1])-0.05*xr,0.5*(z[0]+z[1])+0.1*yr,
                    #             r'$BO^{\pi\pi}=%3.2f$' %pp,fontsize=16)
                    #    print('f_Ebond(%5.3f,%5.3f,%5.3f)=%5.3f' %(si,pi,pp,eb))
                    #    Di = ir.Delta[i]-ir.bo0[i][j]
                    #    Dj = ir.Delta[j]-ir.bo0[i][j]
                    #    if t>0:
                    #       plt.text(xmin+0.45,0.5*(z[0]+z[1])-0.1*yr,
                    #         r'$f_{Message}^{t=1}(%3.2f,%3.2f,%3.2f)=%3.2f$' %(Di,Dj,ir.bo0[i][j],ir.F[-1][i][j]),
                    #         fontsize=16)
                    #    print('f_BO(%5.3f,%5.3f,%5.3f)=%5.3f' %(Di,Dj,ir.bo0[i][j],ir.F[-1][i][j]))
                    # else:
                    plt.text(
                        0.5 * (y[0] + y[1]) - 0.15 * xr,
                        0.5 * (z[0] + z[1]),
                        r'$(%3.2f,%3.2f,%3.2f)$' %
                        (ir.Hsi[t][i][j], ir.Hpi[t][i][j], ir.Hpp[t][i][j]),
                        fontsize=16)

    ymin_ = min(ymin, yl + 0.1 * yr)
    plt.text(xmin, ymin_, r'$BO^{t=%d}$' % t, fontsize=16)
    plt.savefig('MessagePassing.svg', transparent=True)
Beispiel #8
0
class AtomOP(object):
    def __init__(self, atoms=None, rtole=0.5):
        self.rtole = rtole
        if atoms is None:
            gen_ = 'md.traj' if isfile('md.traj') else 'poscar.gen'
            atoms = read(gen_, index=-1)

        self.ir = IRFF_NP(atoms=atoms,
                          libfile='ffield.json',
                          rcut=None,
                          nn=True)

        self.natom = self.ir.natom
        self.atom_name = self.ir.atom_name
        spec = self.ir.spec

        label_dic = {}
        for sp in self.atom_name:
            if sp in label_dic:
                label_dic[sp] += 1
            else:
                label_dic[sp] = 1
        self.label = ''
        for sp in spec:
            self.label += sp + str(label_dic[sp])

    def check(self, wcheck=2, i=0, atoms=None, rtole=None):
        if atoms is None:
            atoms = self.ir.atoms
        if not rtole is None:
            self.rtole = rtole

        self.ir.calculate_Delta(atoms, updateP=True)

        fc = open('check.log', 'w')
        if i % wcheck == 0:
            atoms = self.checkLoneAtoms(atoms, fc)
        else:
            atoms = self.checkLoneAtom(atoms, fc)

        atoms = self.checkClosedAtom(atoms, fc)
        fc.close()
        return atoms

    def checkLoneAtom(self, atoms, fc):
        for i in range(self.natom):
            if self.ir.Delta[i] <= self.ir.atol:
                print('- find an lone atom', i, self.atom_name[i], file=fc)
                sid = np.argsort(self.ir.r[i])
                for j in sid:
                    if self.ir.r[i][j] > 0.0001:
                        print('  move lone atom to nearest neighbor: %d' % j,
                              file=fc)
                        vr = self.ir.vr[i][j]
                        u = vr / np.sqrt(np.sum(np.square(vr)))
                        atoms.positions[i] = atoms.positions[
                            j] + u * 0.64 * self.ir.r_cuta[i][j]
                        break
                self.ir.calculate_Delta(atoms)
        return atoms

    def checkLoneAtoms(self, atoms, fc):
        for i in range(self.natom):
            if self.ir.Delta[i] <= self.ir.atol:
                print('- find an lone atom', i, self.atom_name[i], file=fc)
                mid = np.argmin(self.ir.ND)

                if mid == i:
                    continue

                print('- find the most atractive atom:', mid, file=fc)
                print('\n- neighors of atom %d %s:' % (i, self.atom_name[i]),
                      end='',
                      file=fc)
                neighs = []
                for j, bo in enumerate(self.ir.bo0[mid]):
                    if bo > self.ir.botol:
                        neighs.append(j)
                        print(j, self.atom_name[j], end='', file=fc)
                print(' ', file=fc)

                if len(neighs) == 0:
                    vr = self.ir.vr[mid][i]
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    atoms.positions[i] = atoms.positions[
                        mid] + u * 0.64 * self.ir.r_cuta[i][mid]
                elif len(neighs) == 1:
                    j = neighs[0]
                    vr = self.ir.vr[mid][j]
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    atoms.positions[i] = atoms.positions[
                        mid] + u * 0.64 * self.ir.r_cuta[i][mid]
                elif len(neighs) == 2:
                    i_, j_ = neighs
                    xj = atoms.positions[mid]
                    xi = 0.5 * (atoms.positions[i_] + atoms.positions[j_])
                    vr = xj - xi
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    vij = atoms.positions[j_] - atoms.positions[i_]
                    rij = np.sqrt(np.sum(np.square(vij)))
                    r_ = np.dot(vij, u)
                    if r_ != rij:
                        atoms.positions[i] = atoms.positions[
                            mid] + u * 0.64 * self.ir.r_cuta[i][mid]
                elif len(neighs) == 3:
                    i_, j_, k_ = neighs
                    vi = atoms.positions[i_] - atoms.positions[j_]
                    vj = atoms.positions[i_] - atoms.positions[k_]
                    # cross product
                    vr = np.cross(vi, vj)
                    c = (atoms.positions[i_] + atoms.positions[j_] +
                         atoms.positions[k_]) / 3
                    v = atoms.positions[mid] - c
                    u = vr / np.sqrt(np.sum(np.square(vr)))
                    # dot product
                    dot = np.dot(v, u)
                    if dot <= 0:
                        u = -u
                    atoms.positions[i] = atoms.positions[
                        mid] + u * 0.64 * self.ir.r_cuta[i][mid]

                self.ir.calculate_Delta(atoms)
        return atoms

    def checkClosedAtom(self, atoms, fc):
        self.ir.calculate_Delta(atoms)
        neighbors = getNeighbor(self.natom, self.ir.r, self.ir.r_cuta)
        for i in range(self.natom - 1):
            for j in range(i + 1, self.natom):
                if self.ir.r[i][j] < self.rtole * self.ir.r_cuta[i][j]:
                    print('- atoms %d and %d too closed' % (i, j), file=fc)

                    moveDirection = self.ir.vr[j][i] / self.ir.r[i][j]
                    moveD = self.ir.r_cuta[i][j] * (self.rtole +
                                                    0.01) - self.ir.r[i][j]
                    moveV = moveD * moveDirection

                    ToBeMove = []
                    ToBeMove = getAtomsToMove(i, j, ToBeMove, neighbors)
                    print('  atoms to to be moved:', ToBeMove, file=fc)
                    for m in ToBeMove:
                        newPos = atoms.positions[m] + moveV
                        r = np.sqrt(
                            np.sum(np.square(newPos - atoms.positions[i])))
                        if r > self.ir.r[i][m]:
                            atoms.positions[m] = newPos
                    self.ir.calculate_Delta(atoms)
                    neighbors = getNeighbor(self.natom, self.ir.r,
                                            self.ir.r_cuta)
        return atoms

    def stretch(self, pairs, nbin=20, scale=1.2, wtraj=False):
        atoms = self.ir.atoms
        self.ir.calculate_Delta(atoms)
        neighbors = getNeighbor(self.natom, self.ir.r, scale * self.ir.re)
        images = []

        if wtraj: his = TrajectoryWriter('stretch.traj', mode='w')
        for pair in pairs:
            i, j = pair
            ToBeMove = []
            ToBeMove = getAtomsToMove(i, j, ToBeMove, neighbors)

            bin_ = (self.ir.r_cuta[i][j] -
                    self.ir.re[i][j] * self.rtole) / nbin
            moveDirection = self.ir.vr[j][i] / self.ir.r[i][j]

            for n in range(nbin):
                atoms_ = atoms.copy()
                moveV = atoms.positions[i] + moveDirection * (
                    self.ir.re[i][j] * self.rtole +
                    bin_ * n) - atoms.positions[j]
                # print(self.ir.re[i][j]*self.rtole+bin_*n)
                for m in ToBeMove:
                    # sPos   = atoms.positions[i] + self.ir.re[i][m]*self.rtole*moveDirection
                    newPos = atoms.positions[m] + moveV
                    r = np.sqrt(np.sum(np.square(newPos - atoms.positions[i])))
                    atoms_.positions[m] = newPos

                self.ir.calculate(atoms_)
                i_ = np.where(
                    np.logical_and(
                        self.ir.r < self.ir.re[i][j] * self.rtole - bin_,
                        self.ir.r > 0.0001))
                n = len(i_[0])
                try:
                    assert n == 0, 'Atoms too closed!'
                except:
                    print('Atoms too closed.')
                    break

                calc = SinglePointCalculator(atoms_, energy=self.ir.E)
                atoms_.set_calculator(calc)
                images.append(atoms_)
                if wtraj: his.write(atoms=atoms_)

        if wtraj: his.close()
        return images

    def close(self):
        self.ir = None
        self.atom_name = None
Beispiel #9
0
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.colors as col
import numpy as np
get_ipython().run_line_magic('matplotlib', 'inline')

images = Trajectory('md.traj')
view(images)
atoms = images[-1]

ir = IRFF_NP(atoms=atoms, libfile='ffield.json', rcut=None, nn=True)
# ir.get_pot_energy(atoms)
# ir.logout()
ir.calculate_Delta(atoms)
# print(ir.ebond)

fig = plt.figure()
ax = fig.gca(projection='3d')

# set figure information
ax.set_title("Bond Energy")
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
mine = np.min(ir.ebond)

print(mine)
cmap = cm.ScalarMappable(col.Normalize(mine, 0.0), cm.rainbow)
Beispiel #10
0
def nxp(gen='C2H4.gen', ffield='ffield.json', nn='T', threshold=0.1):
    atoms = read(gen)
    atom_name = atoms.get_chemical_symbols()
    nn_ = True if nn == 'T' else False

    ir = IRFF_NP(atoms=atoms, libfile=ffield, rcut=None, nn=nn_)
    # ir.get_pot_energy(atoms)
    # ir.logout()
    ir.calculate_Delta(atoms)
    natom = ir.natom

    g = nx.Graph()
    g.clear()
    color = {'C': 'grey', 'H': 'yellow', 'O': 'red', 'N': 'blue'}
    size = {'C': 400, 'H': 150, 'O': 300, 'N': 300}
    nodeColor = []
    nodeSize = []
    labels0, labels1 = {}, {}
    for i in range(natom):
        c = color[atom_name[i]]
        s = size[atom_name[i]]
        nodeColor.append(c)
        nodeSize.append(s)
        g.add_node(atom_name[i] + str(i))
        labels0[atom_name[i] +
                str(i)] = atom_name[i] + str(i) + ':%4.3f' % ir.Deltap[i]
        labels1[atom_name[i] +
                str(i)] = atom_name[i] + str(i) + ':%4.3f' % ir.Delta[i]

    edgew = []
    for i in range(natom - 1):
        for j in range(i + 1, natom):
            if ir.r[i][j] < ir.r_cut[i][j]:
                if ir.bop[i][j] >= threshold:
                    g.add_edge(atom_name[i] + str(i),
                               atom_name[j] + str(j),
                               BO0='%5.4f' % ir.bop[i][j])
                    edgew.append(2.0 * ir.bop[i][j])

    pos = {}  # pos = nx.spring_layout(g)
    for i, a in enumerate(atoms):
        pos[atom_name[i] + str(i)] = [a.x, a.y]

    nx.draw(g,
            pos,
            node_color=nodeColor,
            node_size=nodeSize,
            width=edgew,
            with_labels=False)
    edge_labels = nx.get_edge_attributes(g, 'BO0')
    nx.draw_networkx_edge_labels(g, pos, labels=edge_labels, font_size=8)
    # nx.draw_networkx_labels(g,pos,labels=labels0,font_size=8)

    plt.savefig('%s_bo0.eps' % gen.split('.')[0])
    plt.close()

    g = nx.Graph()
    g.clear()
    for i in range(natom):
        g.add_node(atom_name[i] + str(i))

    edgew = []
    for i in range(natom - 1):
        for j in range(i + 1, natom):
            if ir.r[i][j] < ir.r_cut[i][j]:
                if ir.bo0[i][j] >= threshold:
                    g.add_edge(atom_name[i] + str(i),
                               atom_name[j] + str(j),
                               BO1='%5.4f' % ir.bo0[i][j])
                    edgew.append(2.0 * ir.bo0[i][j])

    nx.draw(g,
            pos,
            node_color=nodeColor,
            node_size=nodeSize,
            width=edgew,
            with_labels=False)
    edge_labels = nx.get_edge_attributes(g, 'BO1')
    nx.draw_networkx_edge_labels(g, pos, labels=edge_labels, font_size=8)
    # nx.draw_networkx_labels(g,pos,labels=labels1,font_size=8)

    plt.savefig('%s_bo1.eps' % gen.split('.')[0])
    plt.close()
    ir.close()
Beispiel #11
0
def deb_eover(images, i=0, j=1, figsize=(16, 10), show=False, print_=True):
    bopsi, boppi, boppp, bo0, bo1, eb = [], [], [], [], [], []
    eo, eu, el, esi, r = [], [], [], [], []
    eo_, eu_, eb_ = [], [], []

    ir = IRFF_NP(atoms=images[0], libfile='ffield.json', nn=True)
    ir.calculate_Delta(images[0])

    for i_, atoms in enumerate(images):
        ir.calculate(atoms)
        bo0.append(ir.bop[i][j])
        bo1.append(ir.bo0[i][j])
        eb.append(ir.ebond[i][j])
        eo.append(ir.Eover)
        eu.append(ir.Eunder)
        r.append(ir.r[i][j])

        if print_:
            print('r: {:6.4f} bo: {:6.4f} eu: {:6.4f} ev: {:6.4f} eb: {:6.4f}'.
                  format(ir.r[i][j], ir.bo0[i][j], ir.Eunder, ir.Eover,
                         ir.ebond[i][j]))

    ebx = np.max(np.abs(eb))
    eb = np.array(eb) / ebx + 1.0

    eox = np.max(np.abs(eo))
    if eox < 0.0001:
        eox = 1.0
    eo = np.array(eo) / eox + 1.0

    eux = np.max(np.abs(eu))
    eu = np.array(eu) / eux + 1.0

    plt.figure(figsize=figsize)
    # plt.plot(r,bo0,alpha=0.8,linewidth=2,linestyle='-',color='g',label=r'$BO^{t=0}$')
    # plt.plot(r,bo1,alpha=0.8,linewidth=2,linestyle='-',color='y',label=r'$BO^{t=1}$')
    plt.plot(r,
             eb,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='r',
             label=r'$E_{bond}$')
    plt.plot(r,
             eo,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='indigo',
             label=r'$E_{over}$ ($E_{over}/%4.2f$)' % eox)
    plt.plot(r,
             eu,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='b',
             label=r'$E_{under}$ ($E_{under}/%4.2f$)' % eux)
    plt.legend(loc='best', edgecolor='yellowgreen')
    plt.savefig('deb_bo.pdf')
    if show: plt.show()
    plt.close()
Beispiel #12
0
def deb_bo(images, i=0, j=1, figsize=(16, 10), print_=False, show=False):
    r, bopsi, boppi, boppp, bo0, bo1, eb, esi = [], [], [], [], [], [], [], []

    ir = IRFF_NP(atoms=images[0], libfile='ffield.json', nn=True)
    ir.calculate_Delta(images[0])

    for i_, atoms in enumerate(images):
        ir.calculate(atoms)

        bopsi.append(ir.eterm1[i][j])
        boppi.append(ir.eterm2[i][j])
        boppp.append(ir.eterm3[i][j])
        bo0.append(ir.bop[i][j])
        bo1.append(ir.bo0[i][j])
        eb.append(ir.ebond[i][j])
        esi.append(ir.esi[i][j])
        r.append(ir.r[i][j])
        if print_:
            print(
                '{:3d}  r: {:6.4f} bo: {:6.4f} Delta: {:6.4f} {:6.4f}'.format(
                    i_, ir.r[i][j], ir.bo0[i][j], ir.Delta[i],
                    ir.Delta[j]))  # self.thet0-self.theta
    emin_ = np.min(eb)
    eb = (emin_ - np.array(eb)) / emin_

    ems = np.min(esi)
    emx = np.max(esi)
    esi = (np.array(esi) - ems) / emx

    plt.figure(figsize=figsize)
    plt.plot(r,
             bopsi,
             alpha=0.8,
             linewidth=2,
             linestyle=':',
             color='k',
             label=r'$BO_p^{\sigma}$')
    plt.plot(r,
             boppi,
             alpha=0.8,
             linewidth=2,
             linestyle='-.',
             color='k',
             label=r'$BO_p^{\pi}$')
    plt.plot(r,
             boppp,
             alpha=0.8,
             linewidth=2,
             linestyle='--',
             color='k',
             label=r'$BO_p^{\pi\pi}$')
    plt.plot(r,
             bo0,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='g',
             label=r'$BO^{t=0}$')
    plt.plot(r,
             bo1,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='y',
             label=r'$BO^{t=1}$')
    plt.plot(r,
             eb,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='r',
             label=r'$E_{bond}$ ($-E_{bond}/%4.2f$)' % -emin_)
    plt.plot(r,
             esi,
             alpha=0.8,
             linewidth=2,
             linestyle='-',
             color='indigo',
             label=r'$E_{esi}$ ($E_{si}/%4.2f$)' % emx)
    plt.legend(loc='best', edgecolor='yellowgreen')
    plt.savefig('deb_bo.pdf')
    if show: plt.show()
    plt.close()
    return r, eb
Beispiel #13
0
def pam(traj,
        color={
            'C': 'grey',
            'H': 'steelblue',
            'O': 'crimson',
            'N': 'dodgerblue'
        },
        size={
            'C': 8000,
            'H': 1200,
            'O': 7000,
            'N': 7000
        },
        bondColor='olive',
        boxColor='steelblue',
        bondWidth=20,
        elev=10,
        azim=120,
        Axis=True,
        Box=True,
        t=1,
        text='edge',
        labelnode=False):
    images = Trajectory(traj)

    atoms = images[0]
    sym = atoms.get_chemical_symbols()

    ir = IRFF_NP(atoms=atoms, libfile='ffield.json', rcut=None, nn=True)
    ir.calculate_Delta(atoms)
    # plot scatter points
    fig, ax = plt.subplots(figsize=(8, 8))
    plt.axis('off')

    mid = int(0.5 * len(images))
    for i_ in [0, -1]:
        atoms = images[i_]
        ir.calculate_Delta(atoms)
        if i_ == 0:
            alp = 0.9
        else:
            alp = 0.3
        for i, atom in enumerate(atoms):
            x_, y_, z_ = [], [], []
            x_.append(atom.x)
            y_.append(atom.y)
            z_.append(atom.z)

            plt.scatter(atom.y,
                        atom.z,
                        c=color[sym[i]],
                        marker='o',
                        s=size[sym[i]],
                        label=sym[i],
                        alpha=alp)

        for i in range(ir.natom - 1):
            for j in range(i + 1, ir.natom):
                if ir.r[i][j] < ir.re[i][j] * 1.25 and ir.ebond[i][j] < -0.01:
                    x = [atoms.positions[i][0], atoms.positions[j][0]]
                    y = [atoms.positions[i][1], atoms.positions[j][1]]
                    z = [atoms.positions[i][2], atoms.positions[j][2]]
                    # plt.plot(y,z,c=bondColor,linewidth=5,alpha=0.8)
                    line = mlines.Line2D(y,
                                         z,
                                         lw=bondWidth * ir.bo0[i][j],
                                         ls='-',
                                         alpha=alp,
                                         color=bondColor)
                    line.set_zorder(0)
                    ax.add_line(line)


#     ax.ylabel('Y', fontdict={'size': 15, 'color': 'b'})
#     ax.xlabel('X', fontdict={'size': 15, 'color': 'b'})
    svg = traj.replace('.traj', '.svg')
    plt.savefig(svg, transparent=True)
Beispiel #14
0
def plbd(traj='md.traj',
         batch_size=50,
         nn=False,
         ffield='ffield.json',
         i=0,
         j=1):
    i = int(i)
    j = int(j)
    images = Trajectory(traj)
    ir = IRFF_NP(atoms=images[0], libfile=ffield, rcut=None, nn=True)

    r, f, bo, bosi, bopsi, sieng, powb, expb = [], [], [], [], [], [], [], []
    bopi, bopp, pieng, ppeng = [], [], [], []

    for atoms in images:
        ir.calculate_Delta(atoms)
        r.append(ir.r[i][j])
        # f.append(ir.F[i][j])

        bo.append(ir.bo0[i][j])
        bosi.append(ir.bosi[i][j])
        bopi.append(ir.bopi[i][j])
        bopp.append(ir.bopp[i][j])

        bopsi.append(ir.bop_si[i][j])

        sieng.append(-ir.sieng[i][j])
        powb.append(ir.powb[i][j])
        expb.append(ir.expb[i][j])
        pieng.append(-ir.pieng[i][j])
        ppeng.append(-ir.ppeng[i][j])

    plt.figure()
    plt.subplot(3, 2, 1)
    plt.plot(r,
             alpha=0.5,
             color='b',
             linestyle='-',
             label="radius@%d-%d" % (i, j))
    plt.legend(loc='best', edgecolor='yellowgreen')

    # plt.subplot(3,2,2)
    # plt.plot(f,alpha=0.5,color='r',
    #                linestyle='-',label="F@%d-%d" %(i,j))
    # plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3, 2, 2)
    plt.plot(bo,
             alpha=0.5,
             color='b',
             linestyle='-',
             label="BO@%d-%d" % (i, j))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 3)
    plt.plot(pieng,
             alpha=0.5,
             color='b',
             linestyle='-',
             label=r"$ebond_{pi}$@%d-%d" % (i, j))
    plt.plot(ppeng,
             alpha=0.5,
             color='k',
             linestyle='-',
             label=r"$ebond_{pp}$@%d-%d" % (i, j))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 4)
    plt.plot(bopsi,
             alpha=0.5,
             color='b',
             linestyle=':',
             label=r"$BO^{'}_{si}$@%d-%d" % (i, j))
    plt.plot(bosi,
             alpha=0.5,
             color='r',
             linestyle='-',
             label=r'$BO_{si}$@%d-%d' % (i, j))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 5)
    plt.plot(sieng,
             alpha=0.5,
             color='r',
             linestyle='-',
             label=r"$ebond_{si}$@%d-%d" % (i, j))
    # plt.plot(pieng,alpha=0.5,color='b',
    #          linestyle='-',label=r"$ebond_{pi}$@%d-%d" %(i,j))
    # plt.plot(ppeng,alpha=0.5,color='k',
    #          linestyle='-',label=r"$ebond_{pp}$@%d-%d" %(i,j))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 6)
    plt.plot(bopi,
             alpha=0.5,
             color='b',
             linestyle='-',
             label=r"$bo_{pi}$@%d-%d" % (i, j))
    plt.plot(bopp,
             alpha=0.5,
             color='r',
             linestyle='-',
             label=r"$bo_{pp}$@%d-%d" % (i, j))
    plt.legend(loc='best', edgecolor='yellowgreen')

    # plt.subplot(3,2,6)
    # plt.plot(powb,alpha=0.5,color='b',
    #          linestyle='-',label=r"$pow_{si}$@%d-%d" %(i,j))
    # plt.plot(expb,alpha=0.5,color='r',
    #          linestyle='-',label=r"$exp_{si}$@%d-%d" %(i,j))
    # plt.legend(loc='best',edgecolor='yellowgreen')

    # plt.subplot(3,2,6)
    # # plt.ylabel(r'$exp$ (eV)')
    # plt.xlabel(r"Step")
    # plt.plot(eterm1[i][j],alpha=0.5,color='b',
    #          linestyle='-',label=r"$exp_{si}$@%d-%d" %(i,j))
    # plt.legend(loc='best',edgecolor='yellowgreen')
    traj_ = traj.split('.')[0]
    plt.savefig('%s_bondorder_%d-%d.eps' % (traj_, i, j), transparent=True)
    plt.close()
Beispiel #15
0
def bde(i=2,j=3,rmin=0.4,ffield='ffield.json',nn='T',gen='poscar.gen'):
    atoms = read(gen)
    nn_=True if nn=='T'  else False
    ir = IRFF_NP(atoms=atoms,
                 libfile=ffield,
                 rcut=None,
                 nn=nn_,massages=1)

    ir.calculate_Delta(atoms)
    natom = ir.natom

    positions = atoms.positions
    v = positions[j] - positions[i]
    r = np.sqrt(np.sum(np.square(v)))
    u = v/r
    # print(u)

    r_,eb,bosi,bop_si,esi,bop,bop_pi,bop_pp,bo = [],[],[],[],[],[],[],[],[]
    e,eba,eo = [],[],[]
    esi,epi,epp = [],[],[]

    for i_ in range(50):
        r = rmin + i_*0.015
        atoms.positions[j] = atoms.positions[i] + u*r
        v = positions[j] - positions[i]
        R = np.sqrt(np.sum(np.square(v)))
        ir.calculate(atoms)
        r_.append(r)
        eb.append(ir.ebond[i][j])
        eba.append(ir.ebond[i][j] + ir.eover[i] + ir.eover[j]) 
        eo.append(ir.eover[i] + ir.eover[j]) 
        bo.append(ir.bo0[i][j])
        bosi.append(ir.bosi[i][j])

        esi.append(-ir.sieng[i][j])
        epi.append(-ir.pieng[i][j])
        epp.append(-ir.ppeng[i][j])

        bop.append(ir.bop[i][j])
        bop_si.append(ir.bop_si[i][j])
        bop_pi.append(ir.bop_pi[i][j])
        bop_pp.append(ir.bop_pp[i][j])

        e.append(ir.E)

    plt.figure()

    plt.subplot(2,2,1)  
    plt.plot(r_,e,label=r'$E_{tot}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(2,2,2)  
    #plt.ylabel( r'$\sigma$ Bond-Energy (eV)')
    # plt.xlabel(r'$Radius$ $(Angstrom)$')
    plt.plot(r_,esi,label=r'$E_{bond}^{\sigma}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(2,2,3)  
    plt.plot(r_,epi,label=r'$E_{bond}^{\pi}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(2,2,4)  
    plt.plot(r_,epp,label=r'$E_{bond}^{\pi\pi}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.savefig('Ebond.eps') 
    plt.close()
Beispiel #16
0
def over(i=2,j=3,rmin=0.4,ffield='ffield.json',nn='T',gen='poscar.gen'):
    atoms = read(gen)
    nn_=True if nn=='T'  else False
    ir = IRFF_NP(atoms=atoms,
                 libfile=ffield,
                 rcut=None,
                 nn=nn_,massages=1)

    ir.calculate_Delta(atoms)
    natom = ir.natom

    positions = atoms.positions
    v = positions[j] - positions[i]
    r = np.sqrt(np.sum(np.square(v)))
    u = v/r
    # print(u)

    r_,eb,bosi,bop_si,bop,bop_pi,bop_pp,bo = [],[],[],[],[],[],[],[]
    eba,eo,dlpi,dlpj,ev,boe = [],[],[],[],[],[]
    esi,epi,epp = [],[],[]
   
    for i_ in range(50):
        r = rmin + i_*0.015
        atoms.positions[j] = atoms.positions[i] + u*r
        v = positions[j] - positions[i]
        R = np.sqrt(np.sum(np.square(v)))
        ir.calculate(atoms)
        r_.append(r)
        eb.append(ir.ebond[i][j])
        eba.append(ir.ebond[i][j] + ir.eover[i] + ir.Evdw) 
        ev.append(ir.Evdw)

        eo.append(ir.eover[i] + ir.eover[j]) 
        bo.append(ir.bo0[i][j])
        bosi.append(ir.bosi[i][j])
        esi.append(-ir.sieng[i][j])
        boe.append(ir.esi[i][j])

        bop.append(ir.bop[i][j])
        bop_si.append(ir.bop_si[i][j])
        bop_pi.append(ir.bop_pi[i][j])
        bop_pp.append(ir.bop_pp[i][j])

        dlpi.append(ir.Delta_lpcorr[i])
        dlpj.append(ir.Delta_lpcorr[j])

    plt.figure()
    plt.subplot(3,2,1)  
    #plt.ylabel( r'$\sigma$ Bond-Energy (eV)')
    # plt.xlabel(r'$Radius$ $(Angstrom)$')
    plt.plot(r_,eb,label=r'$E_{bond}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,2)  
    plt.plot(r_,eba,label=r'$E_{bond}$ +  $E_{vdw}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')


    plt.subplot(3,2,3)  
    plt.plot(r_,bo,label=r'$E_{over}$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')


    plt.subplot(3,2,4)  
    plt.plot(r_,bosi,label=r'$BO_{\sigma}$ t=1', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')


    plt.subplot(3,2,5)  
    plt.plot(r_,boe,label=r'$BO_{\sigma}^e$', color='r', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,6)  
    plt.plot(r_,dlpi,label=r'$\Delta^{i}_{lpcorr}$(%s)' %ir.atom_name[i], 
             color='r', linewidth=2, linestyle='-')
    plt.plot(r_,dlpj,label=r'$\Delta^{j}_{lpcorr}$(%s)' %ir.atom_name[j], 
             color='b', linewidth=2, linestyle='-')
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.savefig('Eover.eps') 
    plt.close()