示例#1
0
    def __generategarbagebox__(self, Nm, Nembed, L, T):
        self.X = np.empty((0, 3), dtype=np.float32)
        self.S = []
        self.C = np.zeros((Nm, 3), dtype=np.float32)

        rint = np.random.randint(len(self.solv_list), size=Nm)
        self.Na = np.zeros(Nm, dtype=np.int32)
        self.ctd = []

        pos = 0
        plc = 0
        for idx, j in enumerate(rint):
            if idx < Nembed:
                ri = np.random.randint(len(self.solu_list), size=1)
                s = self.solu_list[ri[0]]['species']
                xyz = self.solu_list[ri[0]]['coordinates']
                nmc = self.solu_list[ri[0]]['nmdisplacements']
                frc = self.solu_list[ri[0]]['forceconstant']

                nms = nmt.nmsgenerator(xyz, nmc, frc, s, T, minfc=5.0E-2)
                x = nms.get_Nrandom_structures(1)[0]

            else:
                s = self.solv_list[j]['species']
                xyz = self.solv_list[j]['coordinates']
                nmc = self.solv_list[j]['nmdisplacements']
                frc = self.solv_list[j]['forceconstant']

                nms = nmt.nmsgenerator(xyz, nmc, frc, s, T, minfc=5.0E-2)
                x = nms.get_Nrandom_structures(1)[0]

            # Apply a random rotation
            M = rand_rotation_matrix()
            x = np.dot(x, M.T)

            maxd = hdn.generatedmatsd3(x).flatten().max() / 2.0

            Nf = 0
            fail = True
            while fail:
                ctr = np.random.uniform(2.0 * maxd + self.edgepad,
                                        L - 2.0 * maxd - self.edgepad, (3))
                fail = False
                for cid, c in enumerate(self.ctd):
                    if np.linalg.norm(c[0] - ctr) < maxd + c[1] + 10.0:
                        # search for atoms within r angstroms
                        minv = 1000.0
                        for xi in self.X[c[2]:c[2] + self.Na[cid], :]:
                            for xj in x + ctr:
                                dij = np.linalg.norm(xi - xj)
                                if dij < minv:
                                    minv = dij
                        if minv < self.mindist:
                            fail = True
                            Nf += 1

                if not fail:
                    plc += 1
                    #print('Added:',plc)
                    self.ctd.append((ctr, maxd, pos))
                    self.X = np.vstack([self.X, x + ctr])
                    self.Na[idx] = len(s)
                    pos += len(s)
                    #print('Placement Complete...',plc,'-',Nf)
                    self.S.extend(s)
示例#2
0
    def __generategarbagebox__(self, Nm, L, T):
        self.X = np.empty((0, 3), dtype=np.float32)
        self.S = []
        self.C = np.zeros((Nm, 3), dtype=np.float32)

        rint = np.random.randint(len(self.mols), size=Nm)
        self.Na = np.zeros(Nm, dtype=np.int32)
        self.ctd = []

        pos = 0
        plc = 0
        attempts = 0
        for idx, j in enumerate(rint):
            if attempts >= 10000:
                break
            #x = self.mols[j]['coordinates']
            #s = self.mols[j]['species']

            s = self.mols[j]['species']
            xyz = self.mols[j]['coordinates']
            nmc = self.mols[j]['nmdisplacements']
            frc = self.mols[j]['forceconstant']

            nms = nmt.nmsgenerator(xyz, nmc, frc, s, T, minfc=5.0E-2)
            x = nms.get_Nrandom_structures(1)[0]

            # Apply a random rotation
            M = rand_rotation_matrix()
            x = np.dot(x, M.T)

            maxd = hdn.generatedmatsd3(x).flatten().max() / 2.0
            #print('after:', maxd)

            fail = True
            while fail and attempts < 10000:
                ctr = np.random.uniform(2.0 * maxd + 1.0, L - 2.0 * maxd - 1.0,
                                        (3))
                fail = False
                for cid, c in enumerate(self.ctd):
                    if np.linalg.norm(c[0] - ctr) < maxd + c[1] + 10.0:
                        # search for atoms within r angstroms
                        minv = 1000.0
                        for xi in self.X[c[2]:c[2] + self.Na[cid], :]:
                            for xj in x + ctr:
                                dij = np.linalg.norm(xi - xj)
                                if dij < minv:
                                    minv = dij
                        if minv < 1.5:
                            fail = True
                            attempts += 1

                if not fail:
                    plc += 1
                    attempts = 0
                    #print('Added:',plc)
                    self.ctd.append((ctr, maxd, pos))
                    self.X = np.vstack([self.X, x + ctr])
                    self.Na[idx] = len(s)
                    pos += len(s)
                    self.S.extend(s)

        self.Na = self.Na[0:plc]
示例#3
0
nc = pync.molecule(cnstfile, saefile, nnfdir, 0)

mol = Atoms(spc, xyz, calculator=ANI(False))
mol.calc.setnc(nc)
LBFGS(mol).run(fmax=0.00001)
vib = Vibrations(mol)
vib.run()
vib.summary()

print(xyz)
xyz = mol.get_positions().copy()
print(xyz)

nm_cr = vib.modes[6:]

Nf = 3 * len(spc) - 6
nmo = nm_cr.reshape(Nf, len(spc), 3)

fcc = np.array([
    1.314580, 1.3147106, 1.3149728, 1.5161799, 1.5164505, 5.6583018, 6.7181139,
    6.7187967, 6.7193842
])

gen = nm.nmsgenerator(xyz, nmo, fcc, spc, 2000.0)

N = 2000
gen_crd = np.zeros((N, len(spc), 3), dtype=np.float32)
for i in range(N):
    gen_crd[i] = gen.get_random_structure()

hdt.writexyzfile('pynmstesting.xyz', gen_crd, spc)
示例#4
0
ids.sort()

of = open(cdir + 'kept_data.nfo', 'w')
for i in ids:
    data = l_dat[i]
    f = files[i]
    of.write(f + '\n')
    of.flush()
    #print (data)

    spc = data["species"]
    xyz = data["coordinates"]
    nmc = data["nmdisplacements"]
    frc = data["forceconstant"]

    nms = nmt.nmsgenerator(xyz, nmc, frc, spc, T, minfc=1.0E-2)

    conformers = []
    for i in range(Ngen):
        conformers.append(nms.get_random_structure())
    conformers = np.stack(conformers)

    nc.setConformers(confs=conformers, types=list(spc))
    Ecmp = nc.energy()  # this generates AEVs

    aevs = np.empty([Ngen, len(rcatoms) * aevsize])
    for m in range(Ngen):
        for j, a in enumerate(rcatoms):
            aevs[m, j * aevsize:(j + 1) * aevsize] = nc.atomicenvironments(
                a, m).copy()
示例#5
0
    def normal_mode_sampling(self, T, Ngen, Nkep, maxd, sig, gpuid):
        of = open(self.ldtdir + self.datdir + '/info_data_nms.nfo', 'w')

        aevsize = self.netdict['aevsize']

        anicv = aat.anicrossvalidationconformer(self.netdict['cnstfile'],
                                                self.netdict['saefile'],
                                                self.netdict['nnfprefix'],
                                                self.netdict['num_nets'],
                                                [gpuid], False)

        dc = aat.diverseconformers(self.netdict['cnstfile'],
                                   self.netdict['saefile'],
                                   self.netdict['nnfprefix'] + '0/networks/',
                                   aevsize, gpuid, False)

        Nkp = 0
        Nkt = 0
        Ntt = 0
        idx = 0
        for di, id in enumerate(self.idir):
            of.write(
                str(di) + ' of ' + str(len(self.idir)) + ') dir: ' + str(id) +
                '\n')
            #print(di,'of',len(self.idir),') dir:', id)
            files = os.listdir(id)
            files.sort()

            Nk = 0
            Nt = 0
            for fi, f in enumerate(files):
                print(f)
                data = hdt.read_rcdb_coordsandnm(id + f)

                #print(id+f)
                spc = data["species"]
                xyz = data["coordinates"]
                nmc = data["nmdisplacements"]
                frc = data["forceconstant"]

                if "charge" in data and "multip" in data:
                    chg = data["charge"]
                    mlt = data["multip"]
                else:
                    chg = "0"
                    mlt = "1"

                nms = nmt.nmsgenerator(xyz,
                                       nmc,
                                       frc,
                                       spc,
                                       T,
                                       minfc=5.0E-2,
                                       maxd=maxd)
                conformers = nms.get_Nrandom_structures(Ngen)

                if conformers.shape[0] > 0:
                    if conformers.shape[0] > Nkep:
                        ids = dc.get_divconfs_ids(conformers, spc, Ngen, Nkep,
                                                  [])
                        conformers = conformers[ids]

                    sigma = anicv.compute_stddev_conformations(conformers, spc)
                    sid = np.where(sigma > sig)[0]

                    Nt += sigma.size
                    Nk += sid.size
                    if 100.0 * sid.size / float(Ngen) > 0:
                        Nkp += sid.size
                        cfn = f.split('.')[0].split('-')[0] + '_' + str(
                            idx).zfill(5) + '-' + f.split('.')[0].split(
                                '-')[1] + '_2.xyz'
                        cmts = [' ' + chg + ' ' + mlt for c in range(Nk)]
                        hdt.writexyzfilewc(self.cdir + cfn, conformers[sid],
                                           spc, cmts)
                idx += 1

            Nkt += Nk
            Ntt += Nt
            of.write('    -Total: ' + str(Nk) + ' of ' + str(Nt) +
                     ' percent: ' + "{:.2f}".format(100.0 * Nk / Nt) + '\n')
            of.flush()
            #print('    -Total:',Nk,'of',Nt,'percent:',"{:.2f}".format(100.0*Nk/Nt))

        del anicv
        del dc

        of.write('\nGrand Total: ' + str(Nkt) + ' of ' + str(Ntt) +
                 ' percent: ' + "{:.2f}".format(100.0 * Nkt / Ntt) + ' Kept ' +
                 str(Nkp) + '\n')
        #print('\nGrand Total:', Nkt, 'of', Ntt,'percent:',"{:.2f}".format(100.0*Nkt/Ntt), 'Kept',Nkp)
        of.close()