5.3.1. ADF fragment job¶
In this module a dedicated job type for ADF fragment analysis is defined. Such an analysis is performed on a molecular system divided into 2 fragments and consists of 3 separate ADF runs: one for each fragment and one for full system.
We define a new job type ADFFragmentJob
by extending MultiJob
.
The constructor (__init__
) of this new job takes 2 more arguments (fragment1
and fragment2
) and one optional argument full_settings
for additional input keywords that are used only in the full system calculation.
In the prerun()
method two fragment jobs and the full system job are created with the proper settings and molecules.
They are then added to the children
list.
The dedicated Results
subclass for ADFFragmentJob
does not provide too much additional functionality.
It simply redirects the usual ADFResults
methods to the results of the full system calculation.
The source code of the whole module with both abovementioned classes:
from ..core.basejob import MultiJob
from ..core.basemol import Molecule
from ..core.results import Results
from ..core.settings import Settings
from ..interfaces.adfsuite.adf import ADFJob
__all__ = ['ADFFragmentJob', 'ADFFragmentResults']
class ADFFragmentResults(Results):
def get_properties(self):
return self.job.full.results.get_properties()
def get_main_molecule(self):
return self.job.full.results.get_main_molecule()
def get_input_molecule(self):
return self.job.full.results.get_input_molecule()
def get_energy(self, unit='au'):
return self.job.full.results.get_energy(unit)
def get_dipole_vector(self, unit='au'):
return self.job.full.results.get_dipole_vector(unit)
def get_energy_decomposition(self, unit='au'):
return self.job.full.results.get_energy_decomposition(unit)
class ADFFragmentJob(MultiJob):
_result_type = ADFFragmentResults
def __init__(self, fragment1=None, fragment2=None, full_settings=None, **kwargs):
MultiJob.__init__(self, **kwargs)
self.fragment1 = fragment1.copy() if isinstance(fragment1, Molecule) else fragment1
self.fragment2 = fragment2.copy() if isinstance(fragment2, Molecule) else fragment2
self.full_settings = full_settings or Settings()
def prerun(self):
self.f1 = ADFJob(name=self.name+'_f1', molecule=self.fragment1, settings=self.settings)
self.f2 = ADFJob(name=self.name+'_f2', molecule=self.fragment2, settings=self.settings)
for at in self.fragment1:
at.properties.adf.fragment = 'subsystem1'
for at in self.fragment2:
at.properties.adf.fragment = 'subsystem2'
self.full = ADFJob(name = self.name + '_full',
molecule = self.fragment1 + self.fragment2,
settings = self.settings + self.full_settings)
self.full.settings.input.fragments.subsystem1 = self.f1
self.full.settings.input.fragments.subsystem2 = self.f2
self.children = [self.f1, self.f2, self.full]
An example usage:
common = Settings() #common settings for all 3 jobs
common.input.basis.type = 'DZP'
common.input.xc.gga = 'PBE'
common.input.symmetry = 'NOSYM'
full = Settings() #additional settings for full system calculation
full.input.etsnocv #empty block
full.input.print = 'etslowdin'
mol1 = Molecule('ethene.xyz')
mol2 = Molecule('butadiene.xyz')
j = ADFFragmentJob(fragment1=mol1, fragment2=mol2,
settings=common, full_settings=full)
r = j.run()
print('Energy decomposition:')
decom = r.get_energy_decomposition()
for k in decom:
print(k, decom[k])
print(j.full.results.readkf('NOCV', 'NOCV_eigenvalues_restricted'))