Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from __future__ import print_function, division
import os,unittest,numpy as np
try:
from ase import Atoms
from gpaw import GPAW
fname = os.path.dirname(os.path.abspath(__file__))+'/h2o.gpw'
from gpaw import PoissonSolver
atoms = Atoms('H2O', positions=[[0.0,-0.757,0.587], [0.0,+0.757,0.587], [0.0,0.0,0.0]])
atoms.center(vacuum=3.5)
convergence = {'density': 1e-7} # Increase accuracy of density for ground state
poissonsolver = PoissonSolver(eps=1e-14, remove_moment=1 + 3) # Increase accuracy of Poisson Solver and apply multipole corrections up to l=1
# hgh and sg15 setups works only with minimal basis set!
calc = GPAW(xc='LDA', h=0.3, nbands=6,
convergence=convergence, poissonsolver=poissonsolver,
mode='lcao', txt=None, setups="hgh") # nbands must be equal to norbs (in this case 6)
atoms.set_calculator(calc)
atoms.get_potential_energy() # Do SCF the ground state
calc.write(fname, mode='all') # write DFT output
except:
calc = None
class KnowValues(unittest.TestCase):
def test_sv_after_gpaw(self):
""" init ao_log_c with it radial orbitals from GPAW """
from pyscf.nao import system_vars_c, prod_basis_c
from __future__ import print_function, division
import os,unittest,numpy as np
try:
from ase import Atoms
from gpaw import GPAW
fname = os.path.dirname(os.path.abspath(__file__))+'/h2o.gpw'
from gpaw import PoissonSolver
atoms = Atoms('H2O', positions=[[0.0,-0.757,0.587], [0.0,+0.757,0.587], [0.0,0.0,0.0]])
atoms.center(vacuum=3.5)
convergence = {'density': 1e-7} # Increase accuracy of density for ground state
poissonsolver = PoissonSolver(eps=1e-14, remove_moment=1 + 3) # Increase accuracy of Poisson Solver and apply multipole corrections up to l=1
# hgh and sg15 setups works only with minimal basis set!
calc = GPAW(xc='LDA', h=0.3, nbands=6,
convergence=convergence, poissonsolver=poissonsolver,
mode='lcao', txt=None, setups="hgh") # nbands must be equal to norbs (in this case 6)
atoms.set_calculator(calc)
atoms.get_potential_energy() # Do SCF the ground state
calc.write(fname, mode='all') # write DFT output
except:
calc = None
class KnowValues(unittest.TestCase):
'DM.Tolerance': 1e-4,
'DM.MixingWeight': 0.01,
'MaxSCFIterations': 150,
'DM.NumberPulay': 4})
H2O.set_calculator(siesta_calc)
efree_siesta = H2O.get_potential_energy()
# run gpaw
from gpaw import GPAW, PoissonSolver
H2O_gp = Atoms("H2O", np.array([[0.0, -0.757, 0.587],
[0.0, +0.757, 0.587],
[0.0, 0.0, 0.0]]))
H2O_gp.center(vacuum=3.5)
convergence = {'density': 1e-7}
poissonsolver = PoissonSolver(eps=1e-14, remove_moment=1 + 3)
gpaw_calc = GPAW(xc='PBE', h=0.3, nbands=6,
convergence=convergence, poissonsolver=poissonsolver,
mode='lcao', setups="sg15", txt=None)
H2O_gp.set_calculator(gpaw_calc)
efree_gpaw = H2O_gp.get_potential_energy()
dft = True
except:
dft = False
class KnowValues(unittest.TestCase):
def test_gpaw_vs_siesta_tddft_iter(self):
def run_if_interactive(self):
if self.structure.calc is None:
kpoints = self.input["kpoints"]
if isinstance(kpoints, str):
kpoints = (
self.input["kpoints"].replace("[", "").replace("]", "").split()
)
self._create_working_directory()
calc = GPAW(
mode=PW(float(self.input["encut"])),
xc=self.input["potential"],
occupations=MethfesselPaxton(width=float(self.input["sigma"])),
kpts=kpoints,
txt=self.working_directory + "/" + self.job_name + ".txt",
)
self.structure.set_calculator(calc)
self.status.running = True
self.structure.calc.calculate(self.structure)
self.interactive_collect()
def run_if_interactive(self):
if self.structure.calc is None:
kpoints = self.input["kpoints"]
if isinstance(kpoints, str):
kpoints = (
self.input["kpoints"].replace("[", "").replace("]", "").split()
)
self._create_working_directory()
calc = GPAW(
mode=PW(float(self.input["encut"])),
xc=self.input["potential"],
occupations=MethfesselPaxton(width=float(self.input["sigma"])),
kpts=kpoints,
txt=self.working_directory + "/" + self.job_name + ".txt",
)
self.structure.set_calculator(calc)
self.status.running = True
self.structure.calc.calculate(self.structure)
self.interactive_collect()
def run_if_interactive(self):
if self.structure.calc is None:
kpoints = self.input["kpoints"]
if isinstance(kpoints, str):
kpoints = (
self.input["kpoints"].replace("[", "").replace("]", "").split()
)
self._create_working_directory()
calc = GPAW(
mode=PW(float(self.input["encut"])),
xc=self.input["potential"],
occupations=MethfesselPaxton(width=float(self.input["sigma"])),
kpts=kpoints,
txt=self.working_directory + "/" + self.job_name + ".txt",
)
self.structure.set_calculator(calc)
self.status.running = True
self.structure.calc.calculate(self.structure)
self.interactive_collect()
gpaw_param = {}
for s in use:
gpaw_param[s] = p[s]
if p["use mixer"]:
mx = getattr(gpaw, p["mixer"])
mx_args = {}
mx_arg_n = ["beta", "nmaxold", "weight"]
if p["mixer"] == "MixerDiff":
mx_arg_n.extend(["beta_m", "nmaxold_m", "weight_m"])
for s in mx_arg_n:
mx_args[s] = p[s]
gpaw_param["mixer"] = mx(**mx_args)
progress = GpawProgressIndicator()
self.gui.simulation["progress"] = progress
gpaw_param["txt"] = progress.get_gpaw_stream()
gpaw_calc = gpaw.GPAW(**gpaw_param)
def gpaw_factory(calc=gpaw_calc):
return calc
self.gui.simulation["calc"] = gpaw_factory
from ase import Atoms
from ase.dft import STM
from gpaw import GPAW
calc = GPAW('Al100.gpw')
a0 = calc.get_atoms()
stm = STM(calc, [0, 1, 2])
c = stm.get_averaged_current(2.5)
h = stm.scan(c)
print h[8]-h[:, 8]
from gpaw import GPAW
calc = GPAW('groundstate.rutile.gpw')
atoms = calc.get_atoms()
path = atoms.cell.bandpath(density=7)
path.write('path.rutile.json')
calc.set(kpts=path, fixdensity=True,
symmetry='off')
atoms.get_potential_energy()
bs = calc.band_structure()
bs.write('bs.rutile.json')
from __future__ import print_function
from ase.io import read
from ase.calculators.socketio import SocketClient
from gpaw import GPAW, Mixer
# The atomic numbers are not transferred over the socket, so we have to
# read the file
atoms = read('initial.traj')
unixsocket = 'ase_server_socket'
atoms.calc = GPAW(mode='lcao',
basis='dzp',
txt='gpaw.client.txt',
mixer=Mixer(0.7, 7, 20.0))
client = SocketClient(unixsocket=unixsocket)
# Each step of the loop changes the atomic positions, but the generator
# yields None.
for i, _ in enumerate(client.irun(atoms, use_stress=False)):
print('step:', i)