-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PyscfCalculation
: Add support to localize orbitals (#56)
The `parameters` input now accepts the `localize_orbitals` key. It accepts a dictionary where the `method` key is required. It should define one of the orbital localization schemes as implemented in PySCF. If defined, the plugin will localize the orbitals and override the molecular orbital coefficients matrix `mean_field_run.mo_coeff`.
- Loading branch information
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
78 changes: 78 additions & 0 deletions
78
tests/calculations/test_base/test_parameters_mean_field_localize_orbitals.pyr
This file contains 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,78 @@ | ||
#!/usr/bin/env python | ||
"""Script automatically generated by `pyscf.base` plugin of `aiida-pyscf`.""" | ||
|
||
|
||
def main(): | ||
import time | ||
|
||
results = { | ||
'timings': {} | ||
} | ||
|
||
time_start = time.perf_counter() | ||
|
||
|
||
# Section: Results | ||
def write_results_and_exit(results): | ||
import dill | ||
import json | ||
import sys | ||
|
||
results['timings']['total'] = time.perf_counter() - time_start | ||
|
||
with open('results.json', 'w') as handle: | ||
json.dump(results, handle) | ||
|
||
with open('model.pickle', 'wb') as handle: | ||
# Need to unset the ``_chkfile`` attribute as it contains an open file handle which cannot be unpickled. | ||
mean_field_run._chkfile = None | ||
# Need to unset the ``opt`` attribute as it contains ctypes objects containing pointers which cannot be pickled. | ||
mean_field_run.opt = None | ||
dill.dump(mean_field_run, handle) | ||
|
||
sys.exit(0) | ||
|
||
# Section: Structure definition | ||
from pyscf import gto | ||
structure = gto.Mole() | ||
structure.unit = 'Ang' | ||
structure.atom = """ | ||
O 0.000000000000000 0.000000000000000 0.119262000000000 | ||
H 0.000000000000000 0.763239000000000 -0.477047000000000 | ||
H 0.000000000000000 -0.763239000000000 -0.477047000000000 | ||
""" | ||
structure.build() | ||
|
||
# Section: Mean field | ||
from pyscf import scf | ||
mean_field = scf.RHF(structure) | ||
mean_field.chkfile = 'checkpoint.chk' | ||
density_matrix = None | ||
mean_field_start = time.perf_counter() | ||
mean_field_run = mean_field.run(density_matrix) | ||
|
||
from pyscf import lo | ||
mean_field_run.mo_coeff = lo.orth_ao(mean_field_run, 'ibo') | ||
results['timings']['mean_field'] = time.perf_counter() - mean_field_start | ||
results['mean_field'] = {} | ||
results['mean_field']['is_converged'] = mean_field_run.converged | ||
results['mean_field']['total_energy'] = mean_field_run.e_tot | ||
results['mean_field']['forces'] = (- mean_field_run.nuc_grad_method().kernel()).tolist() | ||
|
||
if mean_field_run.converged: | ||
results['mean_field']['molecular_orbitals'] = {} | ||
results['mean_field']['molecular_orbitals']['energies'] = mean_field_run.mo_energy.tolist() | ||
results['mean_field']['molecular_orbitals']['labels'] = structure.ao_labels() | ||
results['mean_field']['molecular_orbitals']['occupations'] = mean_field_run.mo_occ.tolist() | ||
else: | ||
write_results_and_exit(results) | ||
|
||
|
||
|
||
|
||
|
||
write_results_and_exit(results) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |