-
Notifications
You must be signed in to change notification settings - Fork 6
Added Natural Transition Orbital calculation and processing. #271
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
79b77a0
added donto flag
AaronH-sys 4307712
retrieve .nto files
AaronH-sys 43118f4
Added NTO calc checkbox and outputs nto files
AaronH-sys b3bea75
Calculation of one specified orbital of s1 nto file
AaronH-sys bbf966e
Added NTO parser, multiple NTO support and cubehandler support from t…
358718b
The workchain to create and compress cube files is now run through th…
d4aba12
Removed redundant code.
8f9af7f
Update README.md
AaronH-sys cebb3ad
Updated the parser function to use the newer, simplified code from th…
1b66170
Merge pull request #1 from AaronH-sys/backendaiidashell
AaronH-sys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Modified from https://github.com/radi0sus/orca_st | ||
|
|
||
| from aiida.engine import calcfunction | ||
| from aiida.orm import Dict | ||
|
|
||
| import re | ||
|
|
||
| @calcfunction | ||
| def parse_orca_output(nto_folder, filename="aiida.out", threshold=0, states="all"): | ||
|
|
||
| #Convert from Aiida nodes to python datatypes if required. | ||
| filename = filename.value | ||
| threshold = threshold.value | ||
| states = states.value | ||
|
|
||
| # global constants | ||
| state_string_start = 'TD-DFT/TDA EXCITED STATES' #check for states from here | ||
| state_string_end = 'TD-DFT/TDA-EXCITATION SPECTRA' #stop reading states from here | ||
| nto_string_start ='NATURAL TRANSITION ORBITALS' #NTOs start here | ||
| found_nto = False #found NTOs in orca.out | ||
|
|
||
| #global lists | ||
| orblist = list() #list of orbital -> orbital transition | ||
| statedict = dict() #dictionary of states with all transitions | ||
| selected_statedict = dict() #dictionary of selected states with all transitions and or with those above the threshold | ||
|
|
||
| #for NTO | ||
| nto_orblist=list() #list of orbital -> orbital transition for NTOs | ||
| nto_statedict=dict() #dictionary of states with all transitions for NTOs | ||
|
|
||
| #check if threshold is between 0 and 100%, reset if not | ||
| if threshold: | ||
| if threshold > 100 or threshold < 0: | ||
| print("Warning! Threshold out of range. Reset to 0.") | ||
| threshold=0 | ||
|
|
||
| #open a file | ||
| #check existence | ||
| try: | ||
| with nto_folder.open(filename) as input_file: | ||
| for line in input_file: | ||
| #start exctract text | ||
| if state_string_start in line: | ||
| for line in input_file: | ||
| #build the state - with several transitions dict: dict[state]=list(orb1 -> orb2, xx%), list(orb3 -> orb4, xx%) | ||
| #first the state | ||
| if re.search(r"STATE\s{1,}(\d{1,}):",line): | ||
| match_state=re.search(r"STATE\s{1,}(\d{1,}):",line) | ||
| #transitions here in orblist | ||
| elif re.search(r"\d{1,}[a,b]\s{1,}->\s{1,}\d{1,}[a,b]",line): | ||
| match_orbs=re.search(r"(\d{1,}[a,b]\s{1,}->\s{1,}\d{1,}[a,b])\s{1,}:\s{1,}(\d{1,}.\d{1,})",line) | ||
| orblist.append((match_orbs.group(1).replace(" "," "),match_orbs.group(2))) | ||
| #add orblist to statedict and clear orblist for next state | ||
| elif re.search(r"^\s*$",line): | ||
| if orblist: | ||
| statedict[match_state.group(1)] = orblist | ||
| orblist=[] | ||
|
|
||
| #exit here | ||
| elif nto_string_start in line: | ||
| break | ||
| elif state_string_end in line: | ||
| break | ||
|
|
||
| #same for NTOs | ||
| if re.search(r"FOR STATE\s{1,}(\d{1,})",line): | ||
| #found NTO in orca.out | ||
| found_nto = True | ||
| match_state_nto=re.search(r"FOR STATE\s{1,}(\d{1,})",line) | ||
| elif re.search(r"\d{1,}[a,b]\s{1,}->\s{1,}\d{1,}[a,b]",line): | ||
| match_orbs_nto=re.search(r"(\d{1,}[a,b]\s{1,}->\s{1,}\d{1,}[a,b])\s{1,}: n=\s{1,}(\d{1,}.\d{1,})",line) | ||
| nto_orblist.append((match_orbs_nto.group(1).replace(" ","").split("->"),match_orbs_nto.group(2))) | ||
|
|
||
| #add orblist to statedict and clear orblist for next state | ||
| elif re.search(r"^\s*$",line): | ||
| if nto_orblist: | ||
| nto_statedict[match_state_nto.group(1)] = nto_orblist | ||
| nto_orblist=[] | ||
|
|
||
| #file not found -> exit here | ||
| except IOError: | ||
| print(f"'{filename}'" + " not found") | ||
| return {} | ||
|
|
||
| #no NTO data in orca.out -> exit here | ||
| if found_nto == False: | ||
| print(f"'{nto_string_start}'" + " not found in " + f"'{filename}'") | ||
| return {} | ||
|
|
||
| #build selected_statedict from statedict with selected states | ||
| try: | ||
| if states == 'all': | ||
| selected_statedict = nto_statedict | ||
|
|
||
| elif re.search(r"\d",states): | ||
| matchstateslist=(re.findall(r"\d+",states)) | ||
| for elements in matchstateslist: | ||
| selected_statedict[elements]=nto_statedict[elements] | ||
|
|
||
| except KeyError: | ||
| print("Warning! State(s) not present. Exit.") | ||
| return {} | ||
|
|
||
| #remove transitions below threshold from selected_statedict | ||
| for elements in selected_statedict: | ||
| transition_list=[] | ||
| for v in selected_statedict[elements]: | ||
| if float(v[1])*100 >= threshold: | ||
| transition_list.append(v) | ||
| selected_statedict[elements]=transition_list | ||
|
|
||
| return Dict(selected_statedict) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this has caused problems for you at the beginning but it works now so please revert this change.