Ejemplo n.º 1
0
 def run(self):
     if self.optg_berny:
         # now optg
         gconv = self.gconvs_berny[self.param['gconv']]
         gradientmax, gradientrms, stepmax, steprms = [ gconv[k] \
               for k in ['gradientmax', 'gradientrms', 'stepmax', 'steprms'] ]
         optimizer = Berny(geomlib.readfile(self.fn+'.xyz'), \
                           gradientmax = gradientmax, \
                           gradientrms = gradientrms, \
                           steprms=steprms, stepmax=stepmax, \
                           maxsteps=self.param['maxit'])
         solver = self.get_energy_and_gradient()
         next(solver)
         coords_a = []
         es_a = []
         grads_a = []
         idx = 0
         for geom in optimizer:
             atoms = list(geom)
             if not isinstance(atoms[0], tuple):
                 atoms = atoms[-1]
             print(' * idx = ', idx)
             #if idx == 0 and (self.gradients is not None):
             #    energy, gradients = self.energy, self.gradients
             #else:
             energy, gradients = solver.send((atoms, None))
             coords_a.append(geom.coords)
             es_a.append(energy)
             grads_a.append(gradients)
             idx += 1
             optimizer.send((energy, gradients))
         self.coords_a = coords_a
         self.grads_a = grads_a
         self.es_a = es_a
         self.coords = coords_a[-1]
         self.gradients = grads_a[-1]
         self.energy = es_a[-1]
     else:
         mol = cc.molecules(self.fn + '.xyz')
         gmol = cmc.RawMol(mol)
         self.get_energy(gmol)
Ejemplo n.º 2
0
def cyanogen():
    return geomlib.readfile(resource_filename('tests', 'cyanogen.xyz'))
Ejemplo n.º 3
0
def aniline():
    return geomlib.readfile(resource_filename('tests', 'aniline.xyz'))
Ejemplo n.º 4
0
def ethanol():
    return geomlib.readfile(resource_filename('tests', 'ethanol.xyz'))
Ejemplo n.º 5
0
from berny import Berny, optimize, geomlib
from berny.solvers import MopacSolver
from scr_old.gradient_plotter import log_berny_plotter
import numpy as np
import sys

# orig_stdout = sys.stdout
srm, smax = 0.05, 0.1
fxyz, logf, fopt = '/home/anastasiia/PycharmProjects/chem_structure/opted_mols/3-MnH2_opted.xyz',\
                   '3_opted'+str(srm)+'_stepmax_'+str(smax)+'.log', '3_opted_'+str(srm)+'_stepmax_'+str(smax)+'.xyz'
f = open(logf, 'w')
sys.stdout = f

optimizer = Berny(geomlib.readfile(fxyz),
                  steprms=srm,
                  stepmax=smax,
                  maxsteps=150)
final = optimize(optimizer, MopacSolver(cmd='/opt/mopac/run_script.sh'))
inertia_princpl = np.linalg.eigvalsh(final.inertia)
final.dump(open('3_berny_opt_mopac.xyz', 'w'), 'xyz')
# final.dump(open('TS-5-6_bopt.xyz', 'w'), 'xyz')
f.close()
log_berny_plotter(logf, title='3_berny_opt_mopac')

# for geom in optimizer:
# get energy and gradients for geom
# optimizer.send((energy, gradients))
Ejemplo n.º 6
0
def water():
    return geomlib.readfile(resource_filename('tests', 'water.xyz')), 7
Ejemplo n.º 7
0
        time.sleep(30)
        print("done sleeping")
        pass

    #load in the etot and gtot
    etot = np.load('energy.npy')
    gtot = np.load('gradient.npy')
    print("energy from .npy = ", etot)
    os.chdir('../')
    return etot, gtot


#start of pyberny optimizer
obj_list[0].write_xyz(coords_name)
os.path.abspath(os.curdir)
optimizer = Berny(geomlib.readfile(os.path.abspath(coords_name)), debug=True)
count = 0
etot_opt = 0
grad_opt = 0
for geom in optimizer:
    print("\n opt cycle:", count, "\n")
    solver = opt_fnc(geom.coords, count)
    count = count + 1
    optimizer.send(solver)
    etot_opt = solver[0]
    grad_opt = solver[1]
relaxed = geom

#writing optimized coords to .xyz file
os.chdir(folder)
coordsname = open("opt_coords.xyz", "w")