Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add orbital tracking #12

Open
YHordijk opened this issue Feb 27, 2024 · 0 comments
Open

Add orbital tracking #12

YHordijk opened this issue Feb 27, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@YHordijk
Copy link
Contributor

YHordijk commented Feb 27, 2024

Often times, when reading orbital data (e.g. energies) we see that MOs can switch ordering. For example, the HOMO at the start of an IRC becomes the HOMO-1 towards the end. This will lead to incorrect data for these orbitals. We should implement an orbital tracking feature that can fix this issue.
The get_alike_orbital method of the pyfmo.Orbitals class allows us to retrieve orbitals that are similar to a given orbital. We can use this feature to fix the above problem statement.

For example:

from pyfmo import Orbitals
from tcutility import pathfunc
import os
import matplotlib.pyplot as plt

# the directory that stores the pyfrag calculations
dirs = pathfunc.get_subdirectories('../../../test/fixtures/pyfrag')
# get the files to the adf.rkf files
files = [os.path.join(d, 'adf.rkf') for d in sorted(dirs, key=lambda d: int(d.split('.')[-1]))]
# and load them
orbs = [Orbitals(f) for f in files]

# plot energy levels of the MOs based on the ordering in the adf.rkf files
plt.plot([orb.mos['HOMO'].energy for orb in orbs], label='HOMO')
plt.plot([orb.mos['HOMO-1'].energy for orb in orbs], label='HOMO-1')
plt.xlabel('IRC Step')
plt.ylabel(r'$\epsilon$ (eV)')
plt.legend()

def MO_track(start_mo, orbs):
    '''
    Function used to track a MO through a series of calculations.
    
    Args:
        start_mo: the MO object that should be tracked through the other calculations.
        orbs: the other orbitals objects that we use to compare to start_mo

    Returns:
        A list of MO objects that are tracked from start_mo
    '''
    mos = [start_mo]
    for orb in orbs[1:]:
        best = orb.get_alike_orbital(mos[-1])
        mos.append(best)
    return mos

# plot the tracked MO energies
plt.figure()
plt.plot([mo.energy for mo in MO_track(orbs[1].mos['HOMO'], orbs[1:-1])], label='HOMO')
plt.plot([mo.energy for mo in MO_track(orbs[1].mos['HOMO-1'], orbs[1:-1])], label='HOMO-1')
plt.xlabel('IRC Step')
plt.ylabel(r'$\epsilon$ (eV)')
plt.legend()
plt.show()

Figure_1
Figure_2

@YHordijk YHordijk added bug Something isn't working enhancement New feature or request labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant