Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Find HOMO level. Note: This could be a very bad
# implementation with fractional occupations if the Fermi
# level was not found otherwise.
all_energies = results['eigenvalues'].ravel()
all_occupations = results['occupations'].ravel()
args = np.argsort(all_energies)
for arg in args[::-1]:
if all_occupations[arg] > 0.1:
break
eFermi = all_energies[arg]
results['efermi'] = eFermi
return results
class Octopus(FileIOCalculator, EigenvalOccupationMixin):
"""Octopus calculator.
The label is always assumed to be a directory."""
implemented_properties = ['energy', 'forces',
'dipole', 'stress',
#'magmom', 'magmoms'
]
troublesome_keywords = set(['subsystemcoordinates',
'subsystems',
'unitsinput',
'unitsoutput',
'pdbcoordinates',
'xyzcoordinates',
'xsfcoordinates',
def set(self, **kwargs):
"""Set octopus input file parameters."""
kwargs = normalize_keywords(kwargs)
if self.octopus_keywords is not None:
self.check_keywords_exist(kwargs)
for keyword in kwargs:
if keyword in self.troublesome_keywords:
msg = ('ASE-Octopus interface will probably misbehave with '
'the %s parameter. Optimists may use '
'Octopus(ignore_troublesome_keywords=[kw1, kw2, ...])'
'to override this.' % keyword)
raise OctopusKeywordError(msg)
changes = FileIOCalculator.set(self, **kwargs)
if changes:
self.results.clear()
self.kwargs.update(kwargs)
# XXX should use 'Parameters' but don't know how
def write_input(self, atoms, properties=None, system_changes=None):
"""Write input (in)-file.
See calculator.py for further details.
Parameters:
atoms : The Atoms object to write.
properties : The properties which should be calculated.
system_changes : List of properties changed since last run.
"""
# Call base calculator.
FileIOCalculator.write_input(
self,
atoms=atoms,
properties=properties,
system_changes=system_changes)
if system_changes is None and properties is None:
return
filename = self.label + '/deMon.inp'
# Start writing the file.
with open(filename, 'w') as fd:
# write keyword argument keywords
value = self.parameters['title']
self._write_argument('TITLE', value, fd)
fd.write('\n')
def write_input(self, atoms, properties=None, system_changes=None):
FileIOCalculator.write_input(self, atoms, properties, system_changes)
self.initialize(atoms)
self.parameters.write(os.path.join(self.directory, 'parameters.ase'))
if 'xctype' in self.parameters:
if 'xc' in self.parameters:
raise RuntimeError("You can't use both 'xctype' and 'xc'!")
if self.parameters.get('autokpt'):
if 'kpts' in self.parameters:
raise RuntimeError("You can't use both 'autokpt' and 'kpts'!")
if 'ngridk' in self.parameters:
raise RuntimeError(
"You can't use both 'autokpt' and 'ngridk'!")
if 'ngridk' in self.parameters:
from ase.calculators.calculator import Calculator, FileIOCalculator, Parameters, kpts2mp, ReadError, all_changes
# Doubtful practice should be more selective in future
from readers import *
from writers import *
from qeio import *
from analyzers import *
import copy
# The exception for the calc runnin but not ready.
class CalcNotReadyError(Exception):
pass
class QuantumEspresso(FileIOCalculator):
"""Class for doing Quantum Espresso calculations.
The default parameters are very close to those that
the QE Fortran code would use. These are the exceptions::
The location of the pseudo potentials is by default
/usr/share/espresso/pseudo
or set from the ESPRESSO_PP_PATH environment variable
The executables are by default pw.x, dos.x ph.x matdyn.x and q2r.x
The calculation can use mpi parallelisation with property 'procs'.
Supported parameters:
'kpts','use_symmetry','procs','label'
CONTROL
'calc','pseudo_dir'
def run_calculation(self, atoms, properties, system_changes):
'''
Hook for the more involved remote calculator to link into.
Actually invokes the parent calculation routine.
'''
# This is restarted calculation do not write anything.
# Nothing to do - just return.
if self.restart : return
FileIOCalculator.calculate(self, atoms, properties, system_changes)
if 'directory' in kwargs:
# If we explicitly set directory, overwrite the one in label.
# XXX: Should we just raise an error here if clash?
directory = kwargs.pop('directory')
label = os.path.join(directory, self.prefix)
self.set_label(label)
if 'txt' in kwargs:
txt = kwargs.pop('txt')
self.set_txt(txt)
if 'atoms' in kwargs:
atoms = kwargs.pop('atoms')
self.set_atoms(atoms) # Resets results
changed_parameters.update(FileIOCalculator.set(self, **kwargs))
# We might at some point add more to changed parameters, or use it
if changed_parameters:
self.results.clear() # We don't want to clear atoms
if kwargs:
# If we make any changes to Vasp input, we always reset
GenerateVaspInput.set(self, **kwargs)
self.results.clear()
>>> 'restart_mode':'restart',
>>> 'verbosity':'high'})
>>> calc.set(kpts={},
>>> input_data=input_data)
>>> calc.calculate(atoms)
3. Make the plot using the BandStructure functionality,
after setting the Fermi level to that of the prior
self-consistent calculation:
>>> bs = calc.band_structure()
>>> bs.reference = fermi_energy
>>> bs.plot()
"""
FileIOCalculator.__init__(self, restart, ignore_bad_restart_file,
label, atoms, **kwargs)
self.calc = None
def write_input(self, atoms, properties=['energies'],
system_changes=all_changes):
"""Write VASP inputfiles, INCAR, KPOINTS and POTCAR"""
# Create the folders where we write the files, if we aren't in the
# current working directory.
FileIOCalculator.write_input(self, atoms, properties, system_changes)
self.initialize(atoms)
GenerateVaspInput.write_input(self, atoms, directory=self.directory)
def get_forces(self, atoms=None):
self.parameters['write_forces'] = True
return FileIOCalculator.get_forces(self, atoms)