コード例 #1
0
    def optimize_rdkit_molecule(self, mrdk, cid, fmax=0.0001, steps=500, logger='opt.out'):
        mol = __convert_rdkitmol_to_aseatoms__(mrdk,cid)
        mol.set_calculator(ANI(False))
        mol.calc.setnc(self.nc)
        dyn = LBFGS(mol,logfile=logger)
        #dyn = LBFGS(mol)
        dyn.run(fmax=fmax,steps=steps)
        stps = dyn.get_number_of_steps()

        xyz = mol.get_positions()
        for i,x in enumerate(xyz):
            mrdk.GetConformer(cid).SetAtomPosition(i,x)
コード例 #2
0
    def optimize_molecule(self, X, S, fmax=0.1, steps=10000, logger='opt.out'):
        mol = Atoms(symbols=S, positions=X)
        mol.set_pbc((False, False, False))
        mol.set_calculator(ANIENS(self.ens))
        dyn = LBFGS(mol,logfile=logger)
        #dyn = LBFGS(mol)
        #dyn = QuasiNewton(mol,logfile=logger)
        dyn.run(fmax=fmax,steps=steps)
        stps = dyn.get_number_of_steps()

        opt = True
        if steps == stps:
            opt = False

        return np.array(mol.get_positions(),dtype=np.float32), opt
コード例 #3
0
def SurfaceEnergy(images, natoms, calc, fmax=0.01, debug=False):
    """Calculate the surface energy from a list of slab images.

    Parameters
    ----------
    images: List of slab images which the calculation is based on. The x and
    y dimensions of the images unit cell must be conserved.

    natoms: Number of atoms in a atomic layer in the slabs.

    calc: Calculator object that can be attached to the images.
    """
    ucell = images[0].get_cell()

    layers = np.zeros(len(images))
    energies = np.zeros(len(images))

    if debug:
        print "Layers   Energy   LBFGS steps"

    for i, atoms in enumerate(images):
        cell = atoms.get_cell()
        if (ucell[0] != cell[0]).any() or (ucell[1] != cell[1]).any():
            raise ValueError(
                "The x and y dimensions of the unit cell must be conserved.")

        atoms.set_calculator(calc)

        dyn = LBFGS(atoms, logfile=None, trajectory=None)
        dyn.run(fmax=fmax, steps=1000)
        assert dyn.converged(), "LBFGS not converged in 100 steps!"

        layers[i] = len(atoms) / natoms
        energies[i] = atoms.get_potential_energy()

        if debug:
            print "%4i%12.3f%10i" % (layers[i], energies[i],
                                     dyn.get_number_of_steps())

    p = polyfit(layers.reshape((-1, 1)), energies, 1)
    surface_energy = p.c[0] / (2 * natoms)
    assert surface_energy > 0.0

    return surface_energy
コード例 #4
0
    def optimize_rdkit_molecule(self, mrdk, cid, fmax=0.1, steps=10000, logger='opt.out'):
        mol = __convert_rdkitmol_to_aseatoms__(mrdk,cid)
        mol.set_pbc((False, False, False))
        mol.set_calculator(ANIENS(self.ens))
        dyn = LBFGS(mol,logfile=logger)
        #dyn = LBFGS(mol)
        #dyn = QuasiNewton(mol,logfile=logger)
        dyn.run(fmax=fmax,steps=steps)
        stps = dyn.get_number_of_steps()

        opt = True
        if steps == stps:
            opt = False

        xyz = mol.get_positions()
        for i,x in enumerate(xyz):
            mrdk.GetConformer(cid).SetAtomPosition(i,x)

        return opt
コード例 #5
0
ファイル: SurfaceEnergies.py プロジェクト: auag92/n2dm
def SurfaceEnergy(images, natoms, calc, fmax=0.01, debug=False):
    """Calculate the surface energy from a list of slab images.

    Parameters
    ----------
    images: List of slab images which the calculation is based on. The x and
    y dimensions of the images unit cell must be conserved.

    natoms: Number of atoms in a atomic layer in the slabs.

    calc: Calculator object that can be attached to the images.
    """
    ucell = images[0].get_cell()

    layers = np.zeros(len(images))
    energies = np.zeros(len(images))

    if debug:
        print "Layers   Energy   LBFGS steps"

    for i, atoms in enumerate(images):
        cell = atoms.get_cell()
        if (ucell[0] != cell[0]).any() or (ucell[1] != cell[1]).any():
            raise ValueError("The x and y dimensions of the unit cell must be conserved.")

        atoms.set_calculator(calc)

        dyn = LBFGS(atoms, logfile=None, trajectory=None)
        dyn.run(fmax=fmax, steps=1000)
        assert dyn.converged(), "LBFGS not converged in 100 steps!"

        layers[i] = len(atoms) / natoms
        energies[i] = atoms.get_potential_energy()

        if debug:
            print "%4i%12.3f%10i" % (layers[i], energies[i], dyn.get_number_of_steps())

    p = polyfit(layers.reshape((-1,1)), energies, 1)
    surface_energy = p.c[0] / (2 * natoms)
    assert surface_energy > 0.0

    return surface_energy
コード例 #6
0
for i, f in enumerate(files):
    data = hdn.read_rcdb_coordsandnm(idir + f)
    X = data['coordinates']
    S = data['species']

    mol = Atoms(positions=X, symbols=S)

    mol.set_calculator(ANI(False))
    mol.calc.setnc(nc)

    dyn = LBFGS(mol, logfile='optimization.log')
    dyn.run(fmax=0.00001, steps=1000)

    X = mol.get_positions()

    Nc = int(f.split(".")[0].split("-")[1])
    Fp = f.split("-")[0]
    smiles = get_smiles(idir + f)

    print(i, 'of', len(files), ':', f, dyn.get_number_of_steps(), Nc)
    hdn.write_rcdb_input(X,
                         S,
                         Nc,
                         sdir,
                         Fp,
                         50,
                         'wb97x/6-31g*',
                         '800.0',
                         fill=4,
                         comment='Smiles: ' + smiles)
コード例 #7
0
            xyz[i, 2] = pos.z
            typ.append(sym)
            tstr += sym
            hbr.append(str(hyb))

        # Set molecule
        geometry = Atoms(tstr, xyz)

        # Setup ANI and calculate single point energy
        geometry.set_calculator(NeuroChem2ASE(nc))

        # Geometry optimization with BFGS
        start_time = time.time()
        dyn = LBFGS(geometry, logfile='logfile.out')
        dyn.run(fmax=0.0001, steps=500)
        Ns = dyn.get_number_of_steps()
        print('[ANI Total time:',
              time.time() - start_time, 'seconds. Steps: ', Ns, ']')

        # Get potential
        E1 = geometry.get_potential_energy()

        # Get geometry
        xyz = geometry.get_positions()
        gt.writexyzfile(dir + 'xyz/mol-' + gdbname + '-' + str(Nmol) + '.xyz',
                        xyz, typ)

        #print('Energy:  ' + str(E1))

        fE.write("{:.10f}".format(E1) + '\n')
        fS.write(Chem.MolToSmiles(m) + '\n')
コード例 #8
0
            xyz[i, 0] = pos.x
            xyz[i, 1] = pos.y
            xyz[i, 2] = pos.z

        mol = Atoms(symbols=spc, positions=xyz)
        mol.set_calculator(ANI(False))
        mol.calc.setnc(nc[0])

        #print(xyz)
        #print(spc)

        #print('Optimize...')
        #start_time = time.time()
        dyn = LBFGS(mol, logfile='logfile.txt')
        dyn.run(fmax=0.001, steps=5000)
        conv = True if dyn.get_number_of_steps() == 10000 else False
        #print('[ANI Total time:', time.time() - start_time, 'seconds]')

        xyz = np.array(mol.get_positions(),
                       dtype=np.float32).reshape(xyz.shape[0], 3)
        xyz2 = np.array(mol.get_positions(),
                        dtype=np.float32).reshape(1, xyz.shape[0], 3)

        if conv:
            print('Failed to converge!!!')

        #print('    SPECIES: ', spc)
        energies = np.zeros((5), dtype=np.float64)
        energies2 = np.zeros((5), dtype=np.float64)

        N = 0
コード例 #9
0
    #print(np.vstack(forces))

    csl = []
    for j in range(0, len(list(spc))):
        print(np.vstack(forces)[:, j, :])
        print(np.sum(np.power(np.vstack(forces)[:, j, :], 2.0), axis=0))
        csm = cosine_similarity(np.vstack(forces)[:, j, :])
        cse = np.mean(np.asarray(csm[np.triu_indices_from(csm, 1)]))
        csl.append((spc[j], cse))

    energies = hdt.hatokcal * energies

    sigma = np.std(energies) / float(len(spc))

    f.write("{:.7f}".format((dyn.get_number_of_steps() * dt) / 1000.0) + ' ' +
            "{:.7f}".format(energies[0]) + ' ' + "{:.7f}".format(energies[1]) +
            ' ' + "{:.7f}".format(energies[2]) + ' ' +
            "{:.7f}".format(energies[3]) + ' ' + "{:.7f}".format(energies[4]) +
            ' ' + "{:.7f}".format(sigma) + '\n')

    ekin = mol.get_kinetic_energy() / len(mol)

    output = '  ' + str(i) + ' (' + str(len(spc)) + ',', "{:.4f}".format(
        ekin / (1.5 * units.kB)), 'K) : stps=' + str(dyn.get_number_of_steps(
        )) + ' : std(kcal/mol)=' + "{:.4f}".format(sigma)
    print(output, csl)
    '''
    if sigma > 0.5:
        vib = Vibrations(mol)
        vib.run()