Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def energy(self):
_dict = {'Demag': 'Demag::Energy',
'Exchange': 'UniformExchange::Energy',
'UniaxialAnisotropy': 'UniaxialAnisotropy::Energy',
'Zeeman': 'FixedZeeman::Energy',
'Hamiltonian': 'RungeKuttaEvolve:evolver:Total energy'}
td = oc.TimeDriver()
td.drive(self.system, derive='energy')
dirname = os.path.join(self.system.name,
f'drive-{self.system.drive_number-1}')
odt_file = max(glob.iglob(os.path.join(dirname, '*.odt')),
key=os.path.getctime)
dt = ut.read(odt_file, rename=False)
return dt[_dict[self.cls]][0]