Skip to content

Commit

Permalink
Merge pull request #57 from xiaoruiDong/logparser_fix
Browse files Browse the repository at this point in the history
Improve Log Parsers
  • Loading branch information
xiaoruiDong authored Sep 7, 2023
2 parents 07f7114 + 5a0ddd1 commit 3b6c2ec
Show file tree
Hide file tree
Showing 8 changed files with 5,974 additions and 893 deletions.
408 changes: 0 additions & 408 deletions ipython/Analyze opt&freq&composite jobs.ipynb

This file was deleted.

390 changes: 0 additions & 390 deletions ipython/Analyze scan&irc jobs.ipynb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
"cells": [
{
"cell_type": "markdown",
"id": "7fcbb47e",
"id": "0b5ce9cd-4493-4fca-bedc-279a4b8e0db4",
"metadata": {},
"source": [
"# A demo for Gaussian output analyzer"
"# A Demo for QM Parser"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c6abcb9f",
"id": "1478c1c4-461a-45eb-ba2a-4c14e8f78ba0",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"# To add this RDMC into PYTHONPATH in case you haven't do it\n",
"sys.path.append(os.path.dirname(os.path.abspath('')))\n",
"\n",
"from rdmc.mol import RDKitMol\n",
"from rdmc.external.gaussian import GaussianLog\n",
"from rdmc.view import mol_viewer, grid_viewer\n",
"from rdmc import RDKitMol\n",
"from rdmc.external.logparser import GaussianLog, ORCALog, QChemLog\n",
"from rdmc.ts import examine_normal_mode\n",
"from rdmc.view import mol_viewer, ts_viewer\n",
"\n",
"\n",
"def general_info(glog):\n",
" print(f'Success?: {glog.success}')\n",
Expand All @@ -42,26 +38,25 @@
},
{
"cell_type": "markdown",
"id": "f1542a7c",
"id": "aa11c9db-3521-4729-b017-98d572378cf0",
"metadata": {},
"source": [
"## Input the path of log file <a id='HOME'></a>\n",
"You need to assign the path to `log`. Some examples are provided. "
"Currently, RDMC has three parsers `GaussianLog`, `QChemLog`, and `ORCALog`.\n",
"You need to assign the path to `log`. Some gaussian results are provided for trying out this notebook. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fad5a463",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"############ EXAMPLES #################\n",
"# CBS-QB3 non-TS\n",
"# non-TS\n",
"log = 'data/well-cbsqb3.out'\n",
"# CBS-QB3 TS\n",
"# TS\n",
"# log = 'data/ts-cbsqb3.out'\n",
"# scan\n",
"# log = 'data/scan.out'\n",
Expand Down Expand Up @@ -144,11 +139,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "0fdf4f3e",
"id": "c5616f45-2fd4-4b03-8c8d-80f63a8d05ee",
"metadata": {},
"outputs": [],
"source": [
"glog.plot_convergence(logy=True, relative=True);"
"glog.plot_opt_convergence(logy=True, relative=True)"
]
},
{
Expand All @@ -164,16 +159,15 @@
"cell_type": "code",
"execution_count": null,
"id": "18fd8354",
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"glog.interact_convergence();"
"glog.interact_opt();"
]
},
{
"cell_type": "markdown",
"id": "de28fbd5",
"metadata": {},
"source": [
"### 1.4 Modify the molecule\n",
Expand All @@ -183,6 +177,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7d9daaac",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -193,25 +188,27 @@
{
"cell_type": "code",
"execution_count": null,
"id": "803f099c",
"metadata": {},
"outputs": [],
"source": [
"# Choose the conformer you want to edit\n",
"conf_id = 90\n",
"conf_id = 4\n",
"\n",
"conf = mol.GetConformer(conf_id)\n",
"############ Edit Conformer #########\n",
"# These numbers correpond to the file \"well-cbsqb3.out\"\n",
"# Bond\n",
"conf.SetBondLength([5, 6], 1.6)\n",
"conf.SetBondLength([4, 11], 1.8)\n",
"\n",
"# Angle\n",
"conf.SetAngleDeg([3, 5, 6], 90)\n",
"conf.SetAngleDeg([3, 4, 11], 100)\n",
"\n",
"# Torsion\n",
"conf.SetTorsionDeg([1, 3, 5, 6], 90)\n",
"conf.SetTorsionDeg([2, 3, 4, 11], 40)\n",
"######################################\n",
"# Visualize\n",
"mol_viewer(mol.ToMolBlock(conf_id), 'sdf').update()"
"mol_viewer(mol, confId=conf_id).update()"
]
},
{
Expand Down Expand Up @@ -302,29 +299,30 @@
"metadata": {},
"outputs": [],
"source": [
"r_idx = 0\n",
"p_idx = 0\n",
"##### INPUT #####\n",
"r_idx, p_idx = 0, 0\n",
"###################\n",
"\n",
"assert (r_idx < len(r_mols)) and (p_idx < len(p_mols)), \"invalid index of reactant/product mol provided\"\n",
"\n",
"ts = glog.get_mol(embed_conformers=False)\n",
"mols_to_view = [ts]\n",
"if r_idx < len(r_mols):\n",
" mols_to_view.insert(0, r_mols[r_idx])\n",
"if p_idx < len(p_mols):\n",
" mols_to_view.append(p_mols[p_idx])\n",
"r_mol, p_mol = r_mols[r_idx], p_mols[p_idx]\n",
"\n",
"entries = len(mols_to_view)\n",
"viewer = grid_viewer(viewer_grid=(1, entries), viewer_size=(300 * entries, 300),)\n",
"for i in range(entries):\n",
" mol_viewer(mols_to_view[i], viewer=viewer, viewer_loc=(0, i))\n",
"print('\\nReactant TS Product')\n",
"\n",
"print('\\nreactant TS product')\n",
"print([mol.ToSmiles() for mol in mols_to_view])\n",
"viewer.show()"
"ts_viewer(r_mol=r_mol, p_mol=p_mol, ts_mol=ts,\n",
" alignment=['r', 'ts', 'p'],\n",
" vertically_aligned=False,\n",
" ts_bond_color=('red', 'green'),\n",
" ts_bond_width=0.1,\n",
" viewer_size=(800, 100),\n",
" atom_index=False,\n",
" ).update()"
]
},
{
"cell_type": "markdown",
"id": "a53baa04",
"metadata": {},
"source": [
"### 2.4 Examine the imaginary frequency\n",
Expand All @@ -333,33 +331,38 @@
"\n",
"- `r_smi`: The atom-labeled smi for the reactant complex.\n",
"- `p_smi`: The atom-labeled smi for the product complex.\n",
"- `amplitude`: The amplitude factor on the displacement matrix.\n",
"- `amplitude`: The amplitude factor on the displacement matrix, usually between 0-1. This analysis is not very sensitive to its value.\n",
"\n",
"[back](#HOME)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32f1777a",
"metadata": {},
"outputs": [],
"source": [
"r_smi = ''\n",
"p_smi = ''\n",
"amplitude = 1."
"# Example based on ts-cbsqb3.output\n",
"r_smi = '[C:1]([C:2]([C:3](=[C:4]([H:13])[H:14])[H:12])([H:9])[H:10])([H:15])([H:16])[H:17].[O:5]=[C:6]([O:7][H:11])[C:8]([H:18])([H:19])[H:20]'\n",
"p_smi = '[C:1]([C:2]([C:3]([C:4]([H:13])([H:14])[O:5][C:6](=[O:7])[C:8]([H:18])([H:19])[H:20])([H:11])[H:12])([H:9])[H:10])([H:15])([H:16])[H:17]'\n",
"amplitude = 0.1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "01b6d150",
"metadata": {},
"outputs": [],
"source": [
"examine_normal_mode(RDKitMol.FromSmiles(r_smi), RDKitMol.FromSmiles(p_smi),\n",
"examine_normal_mode(RDKitMol.FromSmiles(r_smi),\n",
" RDKitMol.FromSmiles(p_smi),\n",
" ts_xyz=glog.converged_geometries[0],\n",
" disp=glog.cclib_results.vibdisps[0],\n",
" amplitude=amplitude, weights=True,\n",
" verbose=True, )"
" amplitude=amplitude,\n",
" weights=True,\n",
" verbose=True,)"
]
},
{
Expand All @@ -377,7 +380,7 @@
"source": [
"### 3.1 Visualize the scan\n",
"- `align_scan`: if align the scanned coordinate to make the animaiton cleaner\n",
"- `align_frag_idx`: which part of the body to align (value should be either 1 or 2)\n",
"- `align_frag_idx`: in the animation, you will see one part of the molecule fixed while the other part moving. this argument sets which part of the body to move (value should be either 1 or 2).\n",
"- `atom_index`: whether to show the atom index\n",
"\n",
"[back](#HOME)"
Expand All @@ -390,7 +393,10 @@
"metadata": {},
"outputs": [],
"source": [
"glog.view_traj(align_scan=True, align_frag_idx=1, atom_index=False, backend='jensen').update();"
"glog.view_traj(align_scan=True,\n",
" align_frag_idx=1,\n",
" atom_index=False,\n",
" backend='openbabel').update();"
]
},
{
Expand Down Expand Up @@ -437,7 +443,9 @@
"cell_type": "code",
"execution_count": null,
"id": "bc8663b5",
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"glog.interact_scan(align_scan=True, align_frag_idx=1, backend='jensen');"
Expand Down Expand Up @@ -525,7 +533,6 @@
"\n",
"Guess the reactants and the products from the IRC results. This requires the IRC job to bidirectional.\n",
"- `index`: the index of the conformer pair that is the distance from the TS. To use the geometries at both ends of the IRC curve, you can assign it to `0`.\n",
"- `as_mol_frags`: Whether to return the results as molecule complexes or as individual molecules. `False` means return as the complexes.\n",
"- `inverse`: Inverse the sequence of the reactant and the product.\n",
"\n",
"There will be messages about SaturateMol, you want to make sure the cell generate `r_mol` and `p_mol` has no failure, while ignore the failure message in the other cell. You may also ignore the SMILES generated for the TS\n",
Expand All @@ -542,7 +549,7 @@
},
"outputs": [],
"source": [
"r_mol, p_mol = glog.guess_rxn_from_irc(index=0, as_mol_frags=False, inverse=False)"
"r_mol, p_mol = glog.guess_rxn_from_irc(index=0, inverse=False)"
]
},
{
Expand All @@ -554,27 +561,17 @@
"source": [
"ts = glog.get_mol(embed_conformers=False)\n",
"\n",
"if not isinstance(r_mol, tuple):\n",
" r_mol, p_mol = (r_mol,), (p_mol,)\n",
"print('\\nReactant TS Product')\n",
"\n",
"mols_to_view = list(r_mol) + [ts] + list(p_mol)\n",
"entries = len(mols_to_view)\n",
"viewer = grid_viewer(viewer_grid=(1, entries), viewer_size=(300 * entries, 300),)\n",
"for i in range(entries):\n",
" mol_viewer(mols_to_view[i], viewer=viewer, viewer_loc=(0, i))\n",
"\n",
"print('\\nreactant TS product')\n",
"print([mol.ToSmiles() for mol in mols_to_view])\n",
"viewer.show()"
"ts_viewer(r_mol=r_mol, p_mol=p_mol, ts_mol=ts,\n",
" alignment=['r', 'ts', 'p'],\n",
" vertically_aligned=False,\n",
" ts_bond_color=('red', 'green'),\n",
" ts_bond_width=0.1,\n",
" viewer_size=(800, 100),\n",
" atom_index=False,\n",
" ).update()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa52451d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -586,7 +583,8 @@
"hash": "f734dd8bb8dba54e055a6b986ac72a1a3509c3dff380149774060d53d7aed57a"
},
"kernelspec": {
"display_name": "Python 3.7.7 64-bit ('arc_env': conda)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
Expand All @@ -599,7 +597,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 3b6c2ec

Please sign in to comment.