MultiOptPy 1.20.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- multioptpy/Calculator/__init__.py +0 -0
- multioptpy/Calculator/ase_calculation_tools.py +424 -0
- multioptpy/Calculator/ase_tools/__init__.py +0 -0
- multioptpy/Calculator/ase_tools/fairchem.py +28 -0
- multioptpy/Calculator/ase_tools/gamess.py +19 -0
- multioptpy/Calculator/ase_tools/gaussian.py +165 -0
- multioptpy/Calculator/ase_tools/mace.py +28 -0
- multioptpy/Calculator/ase_tools/mopac.py +19 -0
- multioptpy/Calculator/ase_tools/nwchem.py +31 -0
- multioptpy/Calculator/ase_tools/orca.py +22 -0
- multioptpy/Calculator/ase_tools/pygfn0.py +37 -0
- multioptpy/Calculator/dxtb_calculation_tools.py +344 -0
- multioptpy/Calculator/emt_calculation_tools.py +458 -0
- multioptpy/Calculator/gpaw_calculation_tools.py +183 -0
- multioptpy/Calculator/lj_calculation_tools.py +314 -0
- multioptpy/Calculator/psi4_calculation_tools.py +334 -0
- multioptpy/Calculator/pwscf_calculation_tools.py +189 -0
- multioptpy/Calculator/pyscf_calculation_tools.py +327 -0
- multioptpy/Calculator/sqm1_calculation_tools.py +611 -0
- multioptpy/Calculator/sqm2_calculation_tools.py +376 -0
- multioptpy/Calculator/tblite_calculation_tools.py +352 -0
- multioptpy/Calculator/tersoff_calculation_tools.py +818 -0
- multioptpy/Constraint/__init__.py +0 -0
- multioptpy/Constraint/constraint_condition.py +834 -0
- multioptpy/Coordinate/__init__.py +0 -0
- multioptpy/Coordinate/polar_coordinate.py +199 -0
- multioptpy/Coordinate/redundant_coordinate.py +638 -0
- multioptpy/IRC/__init__.py +0 -0
- multioptpy/IRC/converge_criteria.py +28 -0
- multioptpy/IRC/dvv.py +544 -0
- multioptpy/IRC/euler.py +439 -0
- multioptpy/IRC/hpc.py +564 -0
- multioptpy/IRC/lqa.py +540 -0
- multioptpy/IRC/modekill.py +662 -0
- multioptpy/IRC/rk4.py +579 -0
- multioptpy/Interpolation/__init__.py +0 -0
- multioptpy/Interpolation/adaptive_interpolation.py +283 -0
- multioptpy/Interpolation/binomial_interpolation.py +179 -0
- multioptpy/Interpolation/geodesic_interpolation.py +785 -0
- multioptpy/Interpolation/interpolation.py +156 -0
- multioptpy/Interpolation/linear_interpolation.py +473 -0
- multioptpy/Interpolation/savitzky_golay_interpolation.py +252 -0
- multioptpy/Interpolation/spline_interpolation.py +353 -0
- multioptpy/MD/__init__.py +0 -0
- multioptpy/MD/thermostat.py +185 -0
- multioptpy/MEP/__init__.py +0 -0
- multioptpy/MEP/pathopt_bneb_force.py +443 -0
- multioptpy/MEP/pathopt_dmf_force.py +448 -0
- multioptpy/MEP/pathopt_dneb_force.py +130 -0
- multioptpy/MEP/pathopt_ewbneb_force.py +207 -0
- multioptpy/MEP/pathopt_gpneb_force.py +512 -0
- multioptpy/MEP/pathopt_lup_force.py +113 -0
- multioptpy/MEP/pathopt_neb_force.py +225 -0
- multioptpy/MEP/pathopt_nesb_force.py +205 -0
- multioptpy/MEP/pathopt_om_force.py +153 -0
- multioptpy/MEP/pathopt_qsm_force.py +174 -0
- multioptpy/MEP/pathopt_qsmv2_force.py +304 -0
- multioptpy/ModelFunction/__init__.py +7 -0
- multioptpy/ModelFunction/avoiding_model_function.py +29 -0
- multioptpy/ModelFunction/binary_image_ts_search_model_function.py +47 -0
- multioptpy/ModelFunction/conical_model_function.py +26 -0
- multioptpy/ModelFunction/opt_meci.py +50 -0
- multioptpy/ModelFunction/opt_mesx.py +47 -0
- multioptpy/ModelFunction/opt_mesx_2.py +49 -0
- multioptpy/ModelFunction/seam_model_function.py +27 -0
- multioptpy/ModelHessian/__init__.py +0 -0
- multioptpy/ModelHessian/approx_hessian.py +147 -0
- multioptpy/ModelHessian/calc_params.py +227 -0
- multioptpy/ModelHessian/fischer.py +236 -0
- multioptpy/ModelHessian/fischerd3.py +360 -0
- multioptpy/ModelHessian/fischerd4.py +398 -0
- multioptpy/ModelHessian/gfn0xtb.py +633 -0
- multioptpy/ModelHessian/gfnff.py +709 -0
- multioptpy/ModelHessian/lindh.py +165 -0
- multioptpy/ModelHessian/lindh2007d2.py +707 -0
- multioptpy/ModelHessian/lindh2007d3.py +822 -0
- multioptpy/ModelHessian/lindh2007d4.py +1030 -0
- multioptpy/ModelHessian/morse.py +106 -0
- multioptpy/ModelHessian/schlegel.py +144 -0
- multioptpy/ModelHessian/schlegeld3.py +322 -0
- multioptpy/ModelHessian/schlegeld4.py +559 -0
- multioptpy/ModelHessian/shortrange.py +346 -0
- multioptpy/ModelHessian/swartd2.py +496 -0
- multioptpy/ModelHessian/swartd3.py +706 -0
- multioptpy/ModelHessian/swartd4.py +918 -0
- multioptpy/ModelHessian/tshess.py +40 -0
- multioptpy/Optimizer/QHAdam.py +61 -0
- multioptpy/Optimizer/__init__.py +0 -0
- multioptpy/Optimizer/abc_fire.py +83 -0
- multioptpy/Optimizer/adabelief.py +58 -0
- multioptpy/Optimizer/adabound.py +68 -0
- multioptpy/Optimizer/adadelta.py +65 -0
- multioptpy/Optimizer/adaderivative.py +56 -0
- multioptpy/Optimizer/adadiff.py +68 -0
- multioptpy/Optimizer/adafactor.py +70 -0
- multioptpy/Optimizer/adam.py +65 -0
- multioptpy/Optimizer/adamax.py +62 -0
- multioptpy/Optimizer/adamod.py +83 -0
- multioptpy/Optimizer/adamw.py +65 -0
- multioptpy/Optimizer/adiis.py +523 -0
- multioptpy/Optimizer/afire_neb.py +282 -0
- multioptpy/Optimizer/block_hessian_update.py +709 -0
- multioptpy/Optimizer/c2diis.py +491 -0
- multioptpy/Optimizer/component_wise_scaling.py +405 -0
- multioptpy/Optimizer/conjugate_gradient.py +82 -0
- multioptpy/Optimizer/conjugate_gradient_neb.py +345 -0
- multioptpy/Optimizer/coordinate_locking.py +405 -0
- multioptpy/Optimizer/dic_rsirfo.py +1015 -0
- multioptpy/Optimizer/ediis.py +417 -0
- multioptpy/Optimizer/eve.py +76 -0
- multioptpy/Optimizer/fastadabelief.py +61 -0
- multioptpy/Optimizer/fire.py +77 -0
- multioptpy/Optimizer/fire2.py +249 -0
- multioptpy/Optimizer/fire_neb.py +92 -0
- multioptpy/Optimizer/gan_step.py +486 -0
- multioptpy/Optimizer/gdiis.py +609 -0
- multioptpy/Optimizer/gediis.py +203 -0
- multioptpy/Optimizer/geodesic_step.py +433 -0
- multioptpy/Optimizer/gpmin.py +633 -0
- multioptpy/Optimizer/gpr_step.py +364 -0
- multioptpy/Optimizer/gradientdescent.py +78 -0
- multioptpy/Optimizer/gradientdescent_neb.py +52 -0
- multioptpy/Optimizer/hessian_update.py +433 -0
- multioptpy/Optimizer/hybrid_rfo.py +998 -0
- multioptpy/Optimizer/kdiis.py +625 -0
- multioptpy/Optimizer/lars.py +21 -0
- multioptpy/Optimizer/lbfgs.py +253 -0
- multioptpy/Optimizer/lbfgs_neb.py +355 -0
- multioptpy/Optimizer/linesearch.py +236 -0
- multioptpy/Optimizer/lookahead.py +40 -0
- multioptpy/Optimizer/nadam.py +64 -0
- multioptpy/Optimizer/newton.py +200 -0
- multioptpy/Optimizer/prodigy.py +70 -0
- multioptpy/Optimizer/purtubation.py +16 -0
- multioptpy/Optimizer/quickmin_neb.py +245 -0
- multioptpy/Optimizer/radam.py +75 -0
- multioptpy/Optimizer/rfo_neb.py +302 -0
- multioptpy/Optimizer/ric_rfo.py +842 -0
- multioptpy/Optimizer/rl_step.py +627 -0
- multioptpy/Optimizer/rmspropgrave.py +65 -0
- multioptpy/Optimizer/rsirfo.py +1647 -0
- multioptpy/Optimizer/rsprfo.py +1056 -0
- multioptpy/Optimizer/sadam.py +60 -0
- multioptpy/Optimizer/samsgrad.py +63 -0
- multioptpy/Optimizer/tr_lbfgs.py +678 -0
- multioptpy/Optimizer/trim.py +273 -0
- multioptpy/Optimizer/trust_radius.py +207 -0
- multioptpy/Optimizer/trust_radius_neb.py +121 -0
- multioptpy/Optimizer/yogi.py +60 -0
- multioptpy/OtherMethod/__init__.py +0 -0
- multioptpy/OtherMethod/addf.py +1150 -0
- multioptpy/OtherMethod/dimer.py +895 -0
- multioptpy/OtherMethod/elastic_image_pair.py +629 -0
- multioptpy/OtherMethod/modelfunction.py +456 -0
- multioptpy/OtherMethod/newton_traj.py +454 -0
- multioptpy/OtherMethod/twopshs.py +1095 -0
- multioptpy/PESAnalyzer/__init__.py +0 -0
- multioptpy/PESAnalyzer/calc_irc_curvature.py +125 -0
- multioptpy/PESAnalyzer/cmds_analysis.py +152 -0
- multioptpy/PESAnalyzer/koopman_analysis.py +268 -0
- multioptpy/PESAnalyzer/pca_analysis.py +314 -0
- multioptpy/Parameters/__init__.py +0 -0
- multioptpy/Parameters/atomic_mass.py +20 -0
- multioptpy/Parameters/atomic_number.py +22 -0
- multioptpy/Parameters/covalent_radii.py +44 -0
- multioptpy/Parameters/d2.py +61 -0
- multioptpy/Parameters/d3.py +63 -0
- multioptpy/Parameters/d4.py +103 -0
- multioptpy/Parameters/dreiding.py +34 -0
- multioptpy/Parameters/gfn0xtb_param.py +137 -0
- multioptpy/Parameters/gfnff_param.py +315 -0
- multioptpy/Parameters/gnb.py +104 -0
- multioptpy/Parameters/parameter.py +22 -0
- multioptpy/Parameters/uff.py +72 -0
- multioptpy/Parameters/unit_values.py +20 -0
- multioptpy/Potential/AFIR_potential.py +55 -0
- multioptpy/Potential/LJ_repulsive_potential.py +345 -0
- multioptpy/Potential/__init__.py +0 -0
- multioptpy/Potential/anharmonic_keep_potential.py +28 -0
- multioptpy/Potential/asym_elllipsoidal_potential.py +718 -0
- multioptpy/Potential/electrostatic_potential.py +69 -0
- multioptpy/Potential/flux_potential.py +30 -0
- multioptpy/Potential/gaussian_potential.py +101 -0
- multioptpy/Potential/idpp.py +516 -0
- multioptpy/Potential/keep_angle_potential.py +146 -0
- multioptpy/Potential/keep_dihedral_angle_potential.py +105 -0
- multioptpy/Potential/keep_outofplain_angle_potential.py +70 -0
- multioptpy/Potential/keep_potential.py +99 -0
- multioptpy/Potential/mechano_force_potential.py +74 -0
- multioptpy/Potential/nanoreactor_potential.py +52 -0
- multioptpy/Potential/potential.py +896 -0
- multioptpy/Potential/spacer_model_potential.py +221 -0
- multioptpy/Potential/switching_potential.py +258 -0
- multioptpy/Potential/universal_potential.py +34 -0
- multioptpy/Potential/value_range_potential.py +36 -0
- multioptpy/Potential/void_point_potential.py +25 -0
- multioptpy/SQM/__init__.py +0 -0
- multioptpy/SQM/sqm1/__init__.py +0 -0
- multioptpy/SQM/sqm1/sqm1_core.py +1792 -0
- multioptpy/SQM/sqm2/__init__.py +0 -0
- multioptpy/SQM/sqm2/calc_tools.py +95 -0
- multioptpy/SQM/sqm2/sqm2_basis.py +850 -0
- multioptpy/SQM/sqm2/sqm2_bond.py +119 -0
- multioptpy/SQM/sqm2/sqm2_core.py +303 -0
- multioptpy/SQM/sqm2/sqm2_data.py +1229 -0
- multioptpy/SQM/sqm2/sqm2_disp.py +65 -0
- multioptpy/SQM/sqm2/sqm2_eeq.py +243 -0
- multioptpy/SQM/sqm2/sqm2_overlapint.py +704 -0
- multioptpy/SQM/sqm2/sqm2_qm.py +578 -0
- multioptpy/SQM/sqm2/sqm2_rep.py +66 -0
- multioptpy/SQM/sqm2/sqm2_srb.py +70 -0
- multioptpy/Thermo/__init__.py +0 -0
- multioptpy/Thermo/normal_mode_analyzer.py +865 -0
- multioptpy/Utils/__init__.py +0 -0
- multioptpy/Utils/bond_connectivity.py +264 -0
- multioptpy/Utils/calc_tools.py +884 -0
- multioptpy/Utils/oniom.py +96 -0
- multioptpy/Utils/pbc.py +48 -0
- multioptpy/Utils/riemann_curvature.py +208 -0
- multioptpy/Utils/symmetry_analyzer.py +482 -0
- multioptpy/Visualization/__init__.py +0 -0
- multioptpy/Visualization/visualization.py +156 -0
- multioptpy/WFAnalyzer/MO_analysis.py +104 -0
- multioptpy/WFAnalyzer/__init__.py +0 -0
- multioptpy/Wrapper/__init__.py +0 -0
- multioptpy/Wrapper/autots.py +1239 -0
- multioptpy/Wrapper/ieip_wrapper.py +93 -0
- multioptpy/Wrapper/md_wrapper.py +92 -0
- multioptpy/Wrapper/neb_wrapper.py +94 -0
- multioptpy/Wrapper/optimize_wrapper.py +76 -0
- multioptpy/__init__.py +5 -0
- multioptpy/entrypoints.py +916 -0
- multioptpy/fileio.py +660 -0
- multioptpy/ieip.py +340 -0
- multioptpy/interface.py +1086 -0
- multioptpy/irc.py +529 -0
- multioptpy/moleculardynamics.py +432 -0
- multioptpy/neb.py +1267 -0
- multioptpy/optimization.py +1553 -0
- multioptpy/optimizer.py +709 -0
- multioptpy-1.20.2.dist-info/METADATA +438 -0
- multioptpy-1.20.2.dist-info/RECORD +246 -0
- multioptpy-1.20.2.dist-info/WHEEL +5 -0
- multioptpy-1.20.2.dist-info/entry_points.txt +9 -0
- multioptpy-1.20.2.dist-info/licenses/LICENSE +674 -0
- multioptpy-1.20.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
import torch
|
|
3
|
+
import copy
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from multioptpy.Utils.calc_tools import Calculationtools, output_partial_hess
|
|
8
|
+
from multioptpy.Parameters.parameter import UnitValueLib, atomic_mass
|
|
9
|
+
|
|
10
|
+
class RedundantInternalCoordinates:
|
|
11
|
+
def __init__(self):
|
|
12
|
+
|
|
13
|
+
return
|
|
14
|
+
|
|
15
|
+
def B_matrix(self, coord):#cartecian coord (atom num × 3)#only constract distance B matrix
|
|
16
|
+
|
|
17
|
+
idx_list = [i for i in range(len(coord))]#1-2, 1-3, ..., (N-2)-N, (N-1)-N
|
|
18
|
+
internal_coord_idx = list(itertools.combinations(idx_list, 2))
|
|
19
|
+
b_mat = np.zeros((len(internal_coord_idx), 3*len(coord)))
|
|
20
|
+
internal_coord_count = 0
|
|
21
|
+
|
|
22
|
+
for i, j in internal_coord_idx:
|
|
23
|
+
norm = np.linalg.norm(coord[i] - coord[j])
|
|
24
|
+
dr_dxi = (coord[i][0] - coord[j][0]) / norm
|
|
25
|
+
dr_dyi = (coord[i][1] - coord[j][1]) / norm
|
|
26
|
+
dr_dzi = (coord[i][2] - coord[j][2]) / norm
|
|
27
|
+
|
|
28
|
+
dr_dxj = -1*(coord[i][0] - coord[j][0]) / norm
|
|
29
|
+
dr_dyj = -1*(coord[i][1] - coord[j][1]) / norm
|
|
30
|
+
dr_dzj = -1*(coord[i][2] - coord[j][2]) / norm
|
|
31
|
+
|
|
32
|
+
b_mat[internal_coord_count][3*i+0] = dr_dxi
|
|
33
|
+
b_mat[internal_coord_count][3*i+1] = dr_dyi
|
|
34
|
+
b_mat[internal_coord_count][3*i+2] = dr_dzi
|
|
35
|
+
|
|
36
|
+
b_mat[internal_coord_count][3*j+0] = dr_dxj
|
|
37
|
+
b_mat[internal_coord_count][3*j+1] = dr_dyj
|
|
38
|
+
b_mat[internal_coord_count][3*j+2] = dr_dzj
|
|
39
|
+
|
|
40
|
+
internal_coord_count += 1
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
return b_mat
|
|
44
|
+
|
|
45
|
+
def G_matrix(self, b_mat):
|
|
46
|
+
return np.dot(b_mat, b_mat.T)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def RICgrad2cartgrad(self, RICgrad, b_mat):
|
|
50
|
+
b_mat_T = b_mat.T
|
|
51
|
+
cartgrad = np.dot(b_mat_T, RICgrad)
|
|
52
|
+
return cartgrad
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def cartgrad2RICgrad(self, cartgrad, b_mat):
|
|
56
|
+
g_mat = self.G_matrix(b_mat)
|
|
57
|
+
#g_mat_inv = np.linalg.inv(g_mat)
|
|
58
|
+
RICgrad = np.linalg.solve(g_mat, np.dot(b_mat, cartgrad))
|
|
59
|
+
#RICgrad = np.dot(g_mat_inv, np.dot(b_mat, cartgrad)) Calculating inverse matrix using np.linalg.inv gives Low-precision results.
|
|
60
|
+
return RICgrad
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def RIChess2carthess(self, cart_coord, connectivity, RIChess, b_mat, RICgrad):
|
|
64
|
+
#cart_coord: Bohr (natom × 3)
|
|
65
|
+
#b_mat: Bohr
|
|
66
|
+
#RIChess: Hartree/Bohr**2
|
|
67
|
+
#RICgrad: Hartree/Bohr
|
|
68
|
+
#connectivity: bond, angle. dihedralangle
|
|
69
|
+
|
|
70
|
+
natom = len(cart_coord)
|
|
71
|
+
K_mat = np.zeros((natom*3, natom*3), dtype="float64")
|
|
72
|
+
count = 0
|
|
73
|
+
bond_connectivity_table = connectivity[0]
|
|
74
|
+
angle_connectivity_table = connectivity[1]
|
|
75
|
+
dihedral_angle_connectivity_table = connectivity[2]
|
|
76
|
+
for idx_list in bond_connectivity_table:
|
|
77
|
+
atom1 = cart_coord[idx_list[0]]
|
|
78
|
+
atom2 = cart_coord[idx_list[1]]
|
|
79
|
+
coord = torch.tensor(np.array([atom1, atom2]) , dtype=torch.float64, requires_grad=True)
|
|
80
|
+
tensor_2nd_derivative_dist = torch.func.hessian(TorchDerivatives().distance)(coord)
|
|
81
|
+
tensor_2nd_derivative_dist = tensor_2nd_derivative_dist.reshape(1, 36)
|
|
82
|
+
second_derivative_dist = copy.copy(tensor_2nd_derivative_dist.detach().numpy())
|
|
83
|
+
second_derivative_dist = np.squeeze(second_derivative_dist)
|
|
84
|
+
|
|
85
|
+
K_mat_idx_list_A = []
|
|
86
|
+
K_mat_idx_list_B = []
|
|
87
|
+
new_idx_list = []
|
|
88
|
+
for idx in idx_list:
|
|
89
|
+
new_idx_list.extend([idx*3, idx*3+1, idx*3+2])
|
|
90
|
+
length = len(new_idx_list)
|
|
91
|
+
for j in new_idx_list:
|
|
92
|
+
K_mat_idx_list_A.extend([j for i in range(length)])
|
|
93
|
+
K_mat_idx_list_B.extend(new_idx_list)
|
|
94
|
+
|
|
95
|
+
K_mat[K_mat_idx_list_A, K_mat_idx_list_B] += second_derivative_dist * RICgrad[count]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
count += 1
|
|
99
|
+
|
|
100
|
+
for idx_list in angle_connectivity_table:
|
|
101
|
+
atom1 = cart_coord[idx_list[0]]
|
|
102
|
+
atom2 = cart_coord[idx_list[1]]
|
|
103
|
+
atom3 = cart_coord[idx_list[2]]
|
|
104
|
+
coord = torch.tensor(np.array([atom1, atom2, atom3]) , dtype=torch.float64, requires_grad=True)
|
|
105
|
+
tensor_2nd_derivative_angle = torch.func.hessian(TorchDerivatives().angle)(coord)
|
|
106
|
+
tensor_2nd_derivative_angle = tensor_2nd_derivative_angle.reshape(1, 81)
|
|
107
|
+
second_derivative_angle = copy.copy(tensor_2nd_derivative_angle.detach().numpy())
|
|
108
|
+
second_derivative_angle = np.squeeze(second_derivative_angle)
|
|
109
|
+
K_mat_idx_list_A = []
|
|
110
|
+
K_mat_idx_list_B = []
|
|
111
|
+
new_idx_list = []
|
|
112
|
+
for idx in idx_list:
|
|
113
|
+
new_idx_list.extend([idx*3, idx*3+1, idx*3+2])
|
|
114
|
+
length = len(new_idx_list)
|
|
115
|
+
for j in new_idx_list:
|
|
116
|
+
K_mat_idx_list_A.extend([j for i in range(length)])
|
|
117
|
+
K_mat_idx_list_B.extend(new_idx_list)
|
|
118
|
+
K_mat[K_mat_idx_list_A, K_mat_idx_list_B] += second_derivative_angle * RICgrad[count]
|
|
119
|
+
|
|
120
|
+
count += 1
|
|
121
|
+
|
|
122
|
+
for idx_list in dihedral_angle_connectivity_table:
|
|
123
|
+
atom1 = cart_coord[idx_list[0]]
|
|
124
|
+
atom2 = cart_coord[idx_list[1]]
|
|
125
|
+
atom3 = cart_coord[idx_list[2]]
|
|
126
|
+
atom4 = cart_coord[idx_list[3]]
|
|
127
|
+
coord = torch.tensor(np.array([atom1, atom2, atom3, atom4]) , dtype=torch.float64, requires_grad=True)
|
|
128
|
+
|
|
129
|
+
tensor_2nd_derivative_dangle = torch.func.hessian(TorchDerivatives().dihedral_angle)(coord)
|
|
130
|
+
tensor_2nd_derivative_dangle = tensor_2nd_derivative_dangle.reshape(1, 144)
|
|
131
|
+
second_derivative_dangle = copy.copy(tensor_2nd_derivative_dangle.detach().numpy())
|
|
132
|
+
second_derivative_dangle = np.squeeze(second_derivative_dangle)
|
|
133
|
+
K_mat_idx_list_A = []
|
|
134
|
+
K_mat_idx_list_B = []
|
|
135
|
+
new_idx_list = []
|
|
136
|
+
for idx in idx_list:
|
|
137
|
+
new_idx_list.extend([idx*3, idx*3+1, idx*3+2])
|
|
138
|
+
length = len(new_idx_list)
|
|
139
|
+
for j in new_idx_list:
|
|
140
|
+
K_mat_idx_list_A.extend([j for i in range(length)])
|
|
141
|
+
K_mat_idx_list_B.extend(new_idx_list)
|
|
142
|
+
K_mat[K_mat_idx_list_A, K_mat_idx_list_B] += second_derivative_dangle * RICgrad[count]
|
|
143
|
+
count += 1
|
|
144
|
+
|
|
145
|
+
cart_hessian = np.dot(np.dot(b_mat.T, RIChess), b_mat) + K_mat
|
|
146
|
+
return cart_hessian
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def partial_stretch_B_matirx(coord, atom_label_1, atom_label_2):#coord:Bohr
|
|
151
|
+
partial_B = []
|
|
152
|
+
natom = len(coord)
|
|
153
|
+
atom_label_1 -= 1
|
|
154
|
+
atom_label_2 -= 1
|
|
155
|
+
norm = np.linalg.norm(coord[atom_label_1] - coord[atom_label_2])
|
|
156
|
+
dr_dxi = (coord[atom_label_1][0] - coord[atom_label_2][0]) / norm
|
|
157
|
+
dr_dyi = (coord[atom_label_1][1] - coord[atom_label_2][1]) / norm
|
|
158
|
+
dr_dzi = (coord[atom_label_1][2] - coord[atom_label_2][2]) / norm
|
|
159
|
+
|
|
160
|
+
dr_dxj = -1*(coord[atom_label_1][0] - coord[atom_label_2][0]) / norm
|
|
161
|
+
dr_dyj = -1*(coord[atom_label_1][1] - coord[atom_label_2][1]) / norm
|
|
162
|
+
dr_dzj = -1*(coord[atom_label_1][2] - coord[atom_label_2][2]) / norm
|
|
163
|
+
|
|
164
|
+
for n in range(natom):
|
|
165
|
+
if n == atom_label_1:
|
|
166
|
+
partial_B.extend([dr_dxi, dr_dyi, dr_dzi])
|
|
167
|
+
elif n == atom_label_2:
|
|
168
|
+
partial_B.extend([dr_dxj, dr_dyj, dr_dzj])
|
|
169
|
+
else:
|
|
170
|
+
partial_B.extend([0.0, 0.0, 0.0])
|
|
171
|
+
|
|
172
|
+
partial_B = np.array([partial_B], dtype="float64")
|
|
173
|
+
return partial_B # Bohr/Bohr
|
|
174
|
+
|
|
175
|
+
def partial_bend_B_matrix(coord, atom_label_1, atom_label_2, atom_label_3):#coord:Bohr
|
|
176
|
+
partial_B = []
|
|
177
|
+
i = atom_label_1 - 1
|
|
178
|
+
j = atom_label_2 - 1
|
|
179
|
+
k = atom_label_3 - 1
|
|
180
|
+
natom = len(coord)
|
|
181
|
+
|
|
182
|
+
vec_ij = coord[i] - coord[j]
|
|
183
|
+
vec_kj = coord[k] - coord[j]
|
|
184
|
+
norm_vec_ij = np.linalg.norm(vec_ij)
|
|
185
|
+
norm_vec_kj = np.linalg.norm(vec_kj)
|
|
186
|
+
|
|
187
|
+
dot_prod = np.dot(vec_ij, vec_kj) / (norm_vec_ij * norm_vec_kj)
|
|
188
|
+
if dot_prod < -1:
|
|
189
|
+
dot_prod = -1
|
|
190
|
+
elif dot_prod > 1:
|
|
191
|
+
dot_prod = 1
|
|
192
|
+
|
|
193
|
+
theta = np.arccos(dot_prod)
|
|
194
|
+
|
|
195
|
+
if abs(theta) > np.pi - 1e-6:
|
|
196
|
+
d_theta_dx = [(np.pi - theta) / (2 * norm_vec_ij ** 2) * vec_ij,
|
|
197
|
+
(1 / norm_vec_ij - 1 / norm_vec_kj) * (np.pi - theta) / (2 * norm_vec_ij) * vec_ij,
|
|
198
|
+
(np.pi -theta) / (2 * norm_vec_kj ** 2) * vec_kj]
|
|
199
|
+
else:
|
|
200
|
+
d_theta_dx = [1 / np.tan(theta) * vec_ij / norm_vec_ij ** 2
|
|
201
|
+
- vec_kj / (norm_vec_ij * norm_vec_kj * np.sin(theta)),
|
|
202
|
+
(vec_ij + vec_kj) / (norm_vec_ij * norm_vec_kj * np.sin(theta))
|
|
203
|
+
- 1 / np.tan(theta) * (vec_ij / norm_vec_ij ** 2 + vec_kj / norm_vec_kj ** 2),
|
|
204
|
+
1 / np.tan(theta) * vec_kj / norm_vec_kj ** 2 - vec_ij / (norm_vec_ij * norm_vec_kj * np.sin(theta))]
|
|
205
|
+
dr_dxi = d_theta_dx[0][0]
|
|
206
|
+
dr_dyi = d_theta_dx[0][1]
|
|
207
|
+
dr_dzi = d_theta_dx[0][2]
|
|
208
|
+
|
|
209
|
+
dr_dxj = d_theta_dx[1][0]
|
|
210
|
+
dr_dyj = d_theta_dx[1][1]
|
|
211
|
+
dr_dzj = d_theta_dx[1][2]
|
|
212
|
+
|
|
213
|
+
dr_dxk = d_theta_dx[2][0]
|
|
214
|
+
dr_dyk = d_theta_dx[2][1]
|
|
215
|
+
dr_dzk = d_theta_dx[2][2]
|
|
216
|
+
|
|
217
|
+
for n in range(natom):
|
|
218
|
+
if n == i:
|
|
219
|
+
partial_B.extend([dr_dxi, dr_dyi, dr_dzi])
|
|
220
|
+
elif n == j:
|
|
221
|
+
partial_B.extend([dr_dxj, dr_dyj, dr_dzj])
|
|
222
|
+
elif n == k:
|
|
223
|
+
partial_B.extend([dr_dxk, dr_dyk, dr_dzk])
|
|
224
|
+
else:
|
|
225
|
+
partial_B.extend([0.0, 0.0, 0.0])
|
|
226
|
+
|
|
227
|
+
partial_B = np.array([partial_B], dtype="float64")
|
|
228
|
+
return partial_B # radian/Bohr
|
|
229
|
+
|
|
230
|
+
def partial_torsion_B_matrix(coord, atom_label_1, atom_label_2, atom_label_3, atom_label_4):
|
|
231
|
+
partial_B = []
|
|
232
|
+
natom = len(coord)
|
|
233
|
+
i = atom_label_1 - 1
|
|
234
|
+
j = atom_label_2 - 1
|
|
235
|
+
k = atom_label_3 - 1
|
|
236
|
+
l = atom_label_4 - 1
|
|
237
|
+
|
|
238
|
+
vec_ij = coord[i] - coord[j]
|
|
239
|
+
vec_lk = coord[l] - coord[k]
|
|
240
|
+
vec_kj = coord[k] - coord[j]
|
|
241
|
+
|
|
242
|
+
norm_vec_kj = np.linalg.norm(vec_kj)
|
|
243
|
+
unit_vec_kj = vec_kj / norm_vec_kj
|
|
244
|
+
|
|
245
|
+
a_1 = vec_ij - np.dot(vec_ij, unit_vec_kj) * unit_vec_kj
|
|
246
|
+
a_2 = vec_lk - np.dot(vec_lk, unit_vec_kj) * unit_vec_kj
|
|
247
|
+
|
|
248
|
+
norm_a_1 = np.linalg.norm(a_1)
|
|
249
|
+
norm_a_2 = np.linalg.norm(a_2)
|
|
250
|
+
|
|
251
|
+
sgn = np.sign(np.linalg.det(np.array([vec_lk, vec_ij, vec_kj])))
|
|
252
|
+
sgn = sgn or 1
|
|
253
|
+
dot_prod = np.dot(a_1, a_2) / (norm_a_1 * norm_a_2)
|
|
254
|
+
if dot_prod < -1:
|
|
255
|
+
dot_prod = -1
|
|
256
|
+
elif dot_prod > 1:
|
|
257
|
+
dot_prod = 1
|
|
258
|
+
phi = np.arccos(dot_prod) * sgn
|
|
259
|
+
|
|
260
|
+
if abs(phi) > np.pi - 1e-6:
|
|
261
|
+
G = np.cross(vec_kj, a_1)
|
|
262
|
+
norm_G = np.linalg.norm(G)
|
|
263
|
+
unit_G = G / norm_G
|
|
264
|
+
A = np.dot(vec_ij, unit_vec_kj) / norm_vec_kj
|
|
265
|
+
B = np.dot(vec_lk, unit_vec_kj) / norm_vec_kj
|
|
266
|
+
|
|
267
|
+
d_phi_dx = [unit_G / norm_a_1,
|
|
268
|
+
- ((1 - A) / norm_a_1 - B / norm_a_2) * unit_G,
|
|
269
|
+
- ((1 + B) / norm_a_2 + A / norm_a_1) * unit_G,
|
|
270
|
+
unit_G / norm_a_2]
|
|
271
|
+
elif abs(phi) < 1e-6:
|
|
272
|
+
G = np.cross(vec_kj, a_1)
|
|
273
|
+
norm_G = np.linalg.norm(G)
|
|
274
|
+
unit_G = G / norm_G
|
|
275
|
+
A = np.dot(vec_ij, unit_vec_kj) / norm_vec_kj
|
|
276
|
+
B = np.dot(vec_lk, unit_vec_kj) / norm_vec_kj
|
|
277
|
+
|
|
278
|
+
d_phi_dx = [unit_G / norm_a_1,
|
|
279
|
+
- ((1 - A) / norm_a_1 - B / norm_a_2) * unit_G,
|
|
280
|
+
- ((1 + B) / norm_a_2 + A / norm_a_1) * unit_G,
|
|
281
|
+
-1 * unit_G / norm_a_2]
|
|
282
|
+
else:
|
|
283
|
+
A = np.dot(vec_ij, unit_vec_kj) / norm_vec_kj
|
|
284
|
+
B = np.dot(vec_lk, unit_vec_kj) / norm_vec_kj
|
|
285
|
+
d_phi_dx = [1/ np.tan(phi) * a_1 / norm_a_1 ** 2 - a_2 / (norm_a_1 * norm_a_2 * np.sin(phi)),
|
|
286
|
+
((1 - A) * a_2 - B * a_1) / (norm_a_1 * norm_a_2 * np.sin(phi)) - 1 / np.tan(phi) * ((1 - A) * a_1 / norm_a_1 ** 2 - B * a_2 / norm_a_2 ** 2),
|
|
287
|
+
((1 + B) * a_1 + A * a_2) / (norm_a_1 * norm_a_2 * np.sin(phi)) - 1 / np.tan(phi) * ((1 + B) * a_2 / norm_a_2 ** 2 + A * a_1 / norm_a_1 ** 2),
|
|
288
|
+
1 / np.tan(phi) * a_2 / norm_a_2 ** 2 - a_1 / (norm_a_1 * norm_a_2 * np.sin(phi))]
|
|
289
|
+
|
|
290
|
+
dr_dxi = d_phi_dx[0][0]
|
|
291
|
+
dr_dyi = d_phi_dx[0][1]
|
|
292
|
+
dr_dzi = d_phi_dx[0][2]
|
|
293
|
+
|
|
294
|
+
dr_dxj = d_phi_dx[1][0]
|
|
295
|
+
dr_dyj = d_phi_dx[1][1]
|
|
296
|
+
dr_dzj = d_phi_dx[1][2]
|
|
297
|
+
|
|
298
|
+
dr_dxk = d_phi_dx[2][0]
|
|
299
|
+
dr_dyk = d_phi_dx[2][1]
|
|
300
|
+
dr_dzk = d_phi_dx[2][2]
|
|
301
|
+
|
|
302
|
+
dr_dxl = d_phi_dx[3][0]
|
|
303
|
+
dr_dyl = d_phi_dx[3][1]
|
|
304
|
+
dr_dzl = d_phi_dx[3][2]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
for n in range(natom):
|
|
308
|
+
if n == i:
|
|
309
|
+
partial_B.extend([dr_dxi, dr_dyi, dr_dzi])
|
|
310
|
+
elif n == j:
|
|
311
|
+
partial_B.extend([dr_dxj, dr_dyj, dr_dzj])
|
|
312
|
+
elif n == k:
|
|
313
|
+
partial_B.extend([dr_dxk, dr_dyk, dr_dzk])
|
|
314
|
+
elif n == l:
|
|
315
|
+
partial_B.extend([dr_dxl, dr_dyl, dr_dzl])
|
|
316
|
+
else:
|
|
317
|
+
partial_B.extend([0.0, 0.0, 0.0])
|
|
318
|
+
|
|
319
|
+
partial_B = np.array([partial_B], dtype="float64")
|
|
320
|
+
return partial_B # radian/Bohr
|
|
321
|
+
|
|
322
|
+
def torch_calc_distance(coord, atom_label_1, atom_label_2):#coord:Bohr
|
|
323
|
+
vec_1 = coord[atom_label_1 - 1]
|
|
324
|
+
vec_2 = coord[atom_label_2 - 1]
|
|
325
|
+
norm = torch.linalg.norm(vec_1 - vec_2)
|
|
326
|
+
return norm
|
|
327
|
+
|
|
328
|
+
def torch_calc_fragm_distance(coord, atom_fragm_1, atom_fragm_2):#fragm_n:tensor
|
|
329
|
+
vec_1 = torch.mean(input=coord[atom_fragm_1 - 1], dim=0)
|
|
330
|
+
vec_2 = torch.mean(input=coord[atom_fragm_2 - 1], dim=0)
|
|
331
|
+
norm = torch.linalg.norm(vec_1 - vec_2)
|
|
332
|
+
return norm
|
|
333
|
+
|
|
334
|
+
def torch_calc_angle(coord, atom_label_1, atom_label_2, atom_label_3):#coord:Bohr
|
|
335
|
+
vec_1 = coord[atom_label_1 - 1]
|
|
336
|
+
vec_2 = coord[atom_label_2 - 1]
|
|
337
|
+
vec_3 = coord[atom_label_3 - 1]
|
|
338
|
+
|
|
339
|
+
vec_12 = vec_1 - vec_2
|
|
340
|
+
vec_32 = vec_3 - vec_2
|
|
341
|
+
norm_vec_12 = torch.linalg.norm(vec_12) + 1e-15
|
|
342
|
+
norm_vec_32 = torch.linalg.norm(vec_32) + 1e-15
|
|
343
|
+
|
|
344
|
+
dot_prod = torch.matmul(vec_12, vec_32) / (norm_vec_12 * norm_vec_32)
|
|
345
|
+
theta = torch.acos(dot_prod)
|
|
346
|
+
return theta
|
|
347
|
+
|
|
348
|
+
def torch_calc_dihedral_angle(coord, atom_label_1, atom_label_2, atom_label_3, atom_label_4):#coord:Bohr
|
|
349
|
+
vec_1 = coord[atom_label_1 - 1]
|
|
350
|
+
vec_2 = coord[atom_label_2 - 1]
|
|
351
|
+
vec_3 = coord[atom_label_3 - 1]
|
|
352
|
+
vec_4 = coord[atom_label_4 - 1]
|
|
353
|
+
|
|
354
|
+
vec_12 = vec_1 - vec_2
|
|
355
|
+
vec_23 = vec_2 - vec_3
|
|
356
|
+
vec_34 = vec_3 - vec_4
|
|
357
|
+
|
|
358
|
+
v1 = torch.linalg.cross(vec_12, vec_23)
|
|
359
|
+
norm_v1 = torch.linalg.norm(v1) + 1e-15
|
|
360
|
+
v2 = torch.linalg.cross(vec_23, vec_34)
|
|
361
|
+
norm_v2 = torch.linalg.norm(v2) + 1e-15
|
|
362
|
+
cos_theta = torch.sum(v1 * v2) / (norm_v1 * norm_v2)
|
|
363
|
+
angle = torch.acos(cos_theta)
|
|
364
|
+
return angle
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def torch_B_matrix(coord, atom_labels, calc_int_coord_func):#coord:Bohr
|
|
368
|
+
B_mat = torch.func.jacrev(calc_int_coord_func)(coord, *atom_labels)
|
|
369
|
+
return B_mat
|
|
370
|
+
|
|
371
|
+
def torch_B_matrix_derivative(coord, atom_labels, calc_int_coord_func):
|
|
372
|
+
B_mat_derivative = torch.func.jacrev(torch_B_matrix)(coord, atom_labels, calc_int_coord_func)
|
|
373
|
+
B_mat_derivative = B_mat_derivative.reshape(3*len(coord), 3*len(coord), 1)
|
|
374
|
+
return B_mat_derivative
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def calc_G_mat(Bmat):
|
|
378
|
+
Gmat = np.dot(Bmat.T, Bmat)
|
|
379
|
+
return Gmat
|
|
380
|
+
|
|
381
|
+
def calc_inv_G_mat(Gmat, threshold=1e-6):
|
|
382
|
+
#Gmat += 1e-12*np.eye(len(Gmat))
|
|
383
|
+
#print(np.linalg.cond(Gmat))
|
|
384
|
+
U, s, VT = np.linalg.svd(Gmat)
|
|
385
|
+
s_inv = []
|
|
386
|
+
for value in s:
|
|
387
|
+
if value > threshold:
|
|
388
|
+
s_inv.append(1/value)
|
|
389
|
+
else:
|
|
390
|
+
s_inv.append(value)
|
|
391
|
+
s_inv = np.array(s_inv, dtype="float64")
|
|
392
|
+
s_inv = np.diag(s_inv)
|
|
393
|
+
Gmat_inv = np.dot(VT.T, np.dot(s_inv, U.T))
|
|
394
|
+
return Gmat_inv
|
|
395
|
+
|
|
396
|
+
def calc_inv_B_mat(Bmat):
|
|
397
|
+
Gmat = calc_G_mat(Bmat)
|
|
398
|
+
Gmat_inv = calc_inv_G_mat(Gmat)
|
|
399
|
+
Bmat_inv = np.dot(Gmat_inv, Bmat.T)
|
|
400
|
+
return Bmat_inv.T
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def calc_dot_B_deriv_int_grad(B_mat_1st_derivative, int_grad):#B_mat_1st_derivative: (3N, 3N, M), int_grad: (M, 1)
|
|
404
|
+
natom3 = len(B_mat_1st_derivative)
|
|
405
|
+
tmp_list = []
|
|
406
|
+
for i in range(natom3):
|
|
407
|
+
tmp_list.append(np.dot(B_mat_1st_derivative[i], int_grad))
|
|
408
|
+
dot_B_deriv_int_grad = np.array(tmp_list, dtype="float64").reshape(natom3, natom3)
|
|
409
|
+
return dot_B_deriv_int_grad
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def calc_int_hess_from_pBmat_for_non_stationary_point(cart_hess, pBmat, pBmat_1st_derivative, int_grad):
|
|
413
|
+
Bmat_inv = calc_inv_B_mat(pBmat)
|
|
414
|
+
dot_B_deriv_int_grad = calc_dot_B_deriv_int_grad(pBmat_1st_derivative, int_grad)
|
|
415
|
+
|
|
416
|
+
int_hess = np.dot(Bmat_inv, np.dot(cart_hess - dot_B_deriv_int_grad, Bmat_inv.T))
|
|
417
|
+
return int_hess
|
|
418
|
+
|
|
419
|
+
def calc_int_cart_coupling_hess_from_pBmat_for_non_stationary_point(cart_hess, pBmat, pBmat_1st_derivative, int_grad):
|
|
420
|
+
Bmat_inv = calc_inv_B_mat(pBmat)
|
|
421
|
+
dot_B_deriv_int_grad = calc_dot_B_deriv_int_grad(pBmat_1st_derivative, int_grad)
|
|
422
|
+
couple_hess = np.dot(Bmat_inv, cart_hess - dot_B_deriv_int_grad)
|
|
423
|
+
return couple_hess
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def calc_cart_hess_from_pBmat_for_non_stationary_point(int_hess, pBmat, pBmat_1st_derivative, int_grad):
|
|
427
|
+
dot_B_deriv_int_grad = calc_dot_B_deriv_int_grad(pBmat_1st_derivative, int_grad)
|
|
428
|
+
cart_hess = np.dot(pBmat.T, np.dot(int_hess, pBmat)) + dot_B_deriv_int_grad
|
|
429
|
+
return cart_hess
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def calc_int_grad_from_pBmat(cart_grad, pBmat):
|
|
433
|
+
Bmat_inv = calc_inv_B_mat(pBmat)
|
|
434
|
+
int_grad = np.dot(Bmat_inv, cart_grad)
|
|
435
|
+
return int_grad
|
|
436
|
+
|
|
437
|
+
def calc_cart_grad_from_pBmat(int_grad, pBmat):
|
|
438
|
+
cart_grad = np.dot(pBmat.T, int_grad)
|
|
439
|
+
return cart_grad
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
class TorchDerivatives:
|
|
443
|
+
def __init__(self):
|
|
444
|
+
return
|
|
445
|
+
|
|
446
|
+
def distance(self, coord):
|
|
447
|
+
dist = torch.linalg.norm(coord[0] - coord[1])
|
|
448
|
+
return dist
|
|
449
|
+
|
|
450
|
+
def angle(self, coord):
|
|
451
|
+
atom1, atom2, atom3 = coord[0], coord[1], coord[2]
|
|
452
|
+
vector1 = atom1 - atom2
|
|
453
|
+
vector2 = atom3 - atom2
|
|
454
|
+
|
|
455
|
+
cos_angle = torch.matmul(vector1, vector2) / (torch.linalg.norm(vector1) * torch.linalg.norm(vector2) + 1e-15)
|
|
456
|
+
angle = torch.arccos(cos_angle)
|
|
457
|
+
|
|
458
|
+
return angle
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def dihedral_angle(self, coord):
|
|
462
|
+
atom1, atom2, atom3, atom4 = coord[0], coord[1], coord[2], coord[3]
|
|
463
|
+
|
|
464
|
+
a1 = atom2 - atom1
|
|
465
|
+
a2 = atom3 - atom2
|
|
466
|
+
a3 = atom4 - atom3
|
|
467
|
+
|
|
468
|
+
v1 = torch.linalg.cross(a1, a2)
|
|
469
|
+
v1 = v1 / torch.linalg.norm(v1, ord=2)
|
|
470
|
+
v2 = torch.linalg.cross(a2, a3)
|
|
471
|
+
v2 = v2 / torch.linalg.norm(v2, ord=2)
|
|
472
|
+
cos_angle = torch.sum(v1*v2) / torch.sum((v1**2) * torch.sum(v2**2) + 1e-15) ** 0.5
|
|
473
|
+
dihedral_angle = torch.arccos(cos_angle)
|
|
474
|
+
|
|
475
|
+
dihedral_angle = torch.abs(dihedral_angle)
|
|
476
|
+
|
|
477
|
+
return dihedral_angle
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def calc_local_fc_from_pBmat(cart_hess, pBmat):#This method is not good since hessian is ill-condition.
|
|
481
|
+
#hessian projected out transion and rotation is needed.
|
|
482
|
+
inv_cart_hess = np.linalg.inv(cart_hess)
|
|
483
|
+
inv_local_fc = np.dot(pBmat, np.dot(inv_cart_hess, pBmat.T))
|
|
484
|
+
local_fc_matrix = np.linalg.inv(inv_local_fc)
|
|
485
|
+
non_diagonal_ufc = np.triu(local_fc_matrix) - np.diag(np.diag(local_fc_matrix))
|
|
486
|
+
non_diagonal_lfc = np.tril(local_fc_matrix) - np.diag(np.diag(local_fc_matrix))
|
|
487
|
+
local_fc = np.diag(local_fc_matrix)
|
|
488
|
+
return local_fc, non_diagonal_ufc, non_diagonal_lfc#a.u.
|
|
489
|
+
|
|
490
|
+
def calc_local_fc_from_pBmat_2(cart_hess, pBmat):#This method is only available to stationary point
|
|
491
|
+
B_inv = np.dot(np.linalg.inv(np.dot(pBmat, pBmat.T)), pBmat)
|
|
492
|
+
local_fc = np.dot(B_inv, np.dot(cart_hess, B_inv.T))
|
|
493
|
+
diag_local_fc = np.diag(local_fc)
|
|
494
|
+
return diag_local_fc
|
|
495
|
+
|
|
496
|
+
def calc_local_fc_from_pBmat_3(cart_hess, pBmat):#This method is only available to stationary point
|
|
497
|
+
#ref.:https://geometric.readthedocs.io/en/latest/how-it-works.html
|
|
498
|
+
B_inv = calc_inv_B_mat(pBmat)
|
|
499
|
+
local_fc = np.dot(B_inv, np.dot(cart_hess, B_inv.T))
|
|
500
|
+
|
|
501
|
+
return local_fc
|
|
502
|
+
|
|
503
|
+
def cartesian_to_z_matrix(cart_coords):
|
|
504
|
+
def calculate_torsion_angle(A, B, C, D):
|
|
505
|
+
AB = B - A
|
|
506
|
+
BC = C - B
|
|
507
|
+
CD = D - C
|
|
508
|
+
|
|
509
|
+
normal_ABC = np.cross(AB, BC)
|
|
510
|
+
normal_BCD = np.cross(BC, CD)
|
|
511
|
+
|
|
512
|
+
normal_ABC = normal_ABC / np.linalg.norm(normal_ABC)
|
|
513
|
+
normal_BCD = normal_BCD / np.linalg.norm(normal_BCD)
|
|
514
|
+
|
|
515
|
+
cosine_angle = np.dot(normal_ABC, normal_BCD)
|
|
516
|
+
angle = np.arccos(cosine_angle)
|
|
517
|
+
|
|
518
|
+
sign = np.dot(np.cross(normal_ABC, normal_BCD), BC)
|
|
519
|
+
if sign < 0:
|
|
520
|
+
angle = -angle
|
|
521
|
+
|
|
522
|
+
return np.degrees(angle)
|
|
523
|
+
n_atoms = len(cart_coords)
|
|
524
|
+
z_matrix = []
|
|
525
|
+
|
|
526
|
+
distance_1_2 = np.linalg.norm(np.array(cart_coords[1]) - np.array(cart_coords[0])) + 1e-15
|
|
527
|
+
z_matrix.append([distance_1_2])
|
|
528
|
+
|
|
529
|
+
distance_1_3 = np.linalg.norm(np.array(cart_coords[2]) - np.array(cart_coords[0])) + 1e-15
|
|
530
|
+
distance_2_3 = np.linalg.norm(np.array(cart_coords[2]) - np.array(cart_coords[1])) + 1e-15
|
|
531
|
+
angle_1_2_3 = np.degrees(np.arccos(np.dot(np.array(cart_coords[1]) - np.array(cart_coords[0]),
|
|
532
|
+
np.array(cart_coords[2]) - np.array(cart_coords[0])) /
|
|
533
|
+
(distance_1_2 * distance_1_3)))
|
|
534
|
+
z_matrix.append([distance_2_3])
|
|
535
|
+
z_matrix.append([angle_1_2_3])
|
|
536
|
+
for i in range(3, n_atoms):
|
|
537
|
+
|
|
538
|
+
distance_i_minus_1 = np.linalg.norm(np.array(cart_coords[i]) - np.array(cart_coords[i-1])) + 1e-15
|
|
539
|
+
distance_i_minus_2 = np.linalg.norm(np.array(cart_coords[i]) - np.array(cart_coords[i-2])) + 1e-15
|
|
540
|
+
clipped_value = np.clip(np.dot(np.array(cart_coords[i-1]) - np.array(cart_coords[i-2]),
|
|
541
|
+
np.array(cart_coords[i]) - np.array(cart_coords[i-1])) /
|
|
542
|
+
(distance_i_minus_2 * distance_i_minus_1), -1, 1)
|
|
543
|
+
angle_i_minus_2_i_minus_1_i = np.degrees(np.arccos(clipped_value))
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
torsion_angle = calculate_torsion_angle(cart_coords[i - 3], cart_coords[i - 2], cart_coords[i - 1], cart_coords[i])
|
|
547
|
+
z_matrix.append([distance_i_minus_1])
|
|
548
|
+
z_matrix.append([angle_i_minus_2_i_minus_1_i])
|
|
549
|
+
z_matrix.append([torsion_angle])
|
|
550
|
+
z_matrix = np.array(z_matrix)
|
|
551
|
+
return z_matrix
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
if __name__ == "__main__":#test
|
|
555
|
+
|
|
556
|
+
test_coord = np.array( [[0.075000142905, 0.075000142905, -0.000000000000],
|
|
557
|
+
[ 1.027799531262, -0.180310974599, 0.000000000000],
|
|
558
|
+
[-0.180310974599, 1.027799531262, 0.000000000000],
|
|
559
|
+
[-0.622488699568, -0.622488699568, 0.000000000000]], dtype="float64") / UnitValueLib().bohr2angstroms
|
|
560
|
+
test_hess = np.array([[ 0.955797621, 0.000024060, -0.000000000, -0.518670978, 0.115520742, 0.000000000, -0.118512045, 0.115518826, 0.000000000, -0.318614598, -0.231063629, -0.000000000],
|
|
561
|
+
[ 0.000024060, 0.955797621, 0.000000000, 0.115518826, -0.118512045, -0.000000000, 0.115520742,-0.518670978 ,-0.000000000,-0.231063629, -0.318614598, 0.000000000],
|
|
562
|
+
[-0.000000000, 0.000000000, -0.016934167, 0.000000000, -0.000000000 , 0.005642447, 0.000000000,-0.000000000, 0.005642447, 0.000000000, 0.000000000, 0.005649274 ],
|
|
563
|
+
[-0.518670978, 0.115518826,0.000000000,0.534121419,-0.123663333,-0.000000000,-0.000671477,-0.007212539, -0.000000000,-0.014778964,0.015357046,-0.000000000],
|
|
564
|
+
[ 0.115520742, -0.118512045,-0.000000000 ,-0.123663333,0.105749196, 0.000000000,0.039787518, -0.000671477,0.000000000,-0.031644928, 0.013434326,-0.000000000],
|
|
565
|
+
[ 0.000000000, -0.000000000,0.005642447,-0.000000000,0.000000000,-0.001877261,-0.000000000,0.000000000,-0.001883273,-0.000000000,0.000000000,-0.001881913],
|
|
566
|
+
[-0.118512045, 0.115520742,0.000000000,-0.000671477,0.039787518, -0.000000000, 0.105749196, -0.123663333,0.000000000,0.013434326,-0.031644928,0.000000000],
|
|
567
|
+
[ 0.115518826, -0.518670978 ,-0.000000000, -0.007212539,-0.000671477,0.000000000, -0.123663333,0.534121419,0.000000000,0.015357046,-0.014778964,0.000000000],
|
|
568
|
+
[ 0.000000000, -0.000000000,0.005642447, -0.000000000,0.000000000,-0.001883273,0.000000000,0.000000000,-0.001877261,0.000000000,0.000000000,-0.001881913],
|
|
569
|
+
[-0.318614598, -0.231063629, 0.000000000,-0.014778964,-0.031644928, -0.000000000,0.013434326,0.015357046,0.000000000,0.319959236,0.247351511,-0.000000000],
|
|
570
|
+
[-0.231063629, -0.318614598, 0.000000000,0.015357046,0.013434326,0.000000000,-0.031644928,-0.014778964,0.000000000,0.247351511, 0.319959236, -0.000000000],
|
|
571
|
+
[-0.000000000, 0.000000000, 0.005649274,-0.000000000, -0.000000000,-0.001881913,0.000000000, 0.000000000,-0.001881913,-0.000000000, -0.000000000,-0.001885447]], dtype="float64")
|
|
572
|
+
test_element_list = ["N", "H", "H", "H"]
|
|
573
|
+
partial_hess, partial_geom, partial_element_list = output_partial_hess(test_hess, [1,2], test_element_list, test_coord)
|
|
574
|
+
p_partial_hess = Calculationtools().project_out_hess_tr_and_rot_for_coord(partial_hess, partial_element_list, partial_geom)
|
|
575
|
+
partial_eigenvalue, partial_eigenvector = np.linalg.eigh(p_partial_hess)
|
|
576
|
+
print(partial_eigenvalue)
|
|
577
|
+
|
|
578
|
+
mw_partial_hess = Calculationtools().project_out_hess_tr_and_rot(partial_hess, partial_element_list, partial_geom)
|
|
579
|
+
partial_eigenvalue, partial_eigenvector = np.linalg.eigh(mw_partial_hess)
|
|
580
|
+
print(partial_eigenvalue)
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
test_mw_hess = copy.copy(Calculationtools().project_out_hess_tr_and_rot(test_hess, test_element_list, test_coord))
|
|
584
|
+
tmp_test_mw_hess = copy.copy(Calculationtools().project_out_hess_tr_and_rot(test_hess, test_element_list, test_coord))
|
|
585
|
+
print("normal coordinate")
|
|
586
|
+
bond_pBmat = partial_stretch_B_matirx(test_coord, 1, 2)
|
|
587
|
+
bend_pBmat = partial_bend_B_matrix(test_coord, 2, 1, 3)
|
|
588
|
+
torsion_pBmat = partial_torsion_B_matrix(test_coord, 2, 1, 3, 4)
|
|
589
|
+
print(bond_pBmat, bend_pBmat, torsion_pBmat)
|
|
590
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(test_hess, bend_pBmat)
|
|
591
|
+
lfc2 = calc_local_fc_from_pBmat_2(test_hess, bend_pBmat)
|
|
592
|
+
print(lfc, undfc, lndfc, lfc2)
|
|
593
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(test_hess, bond_pBmat)
|
|
594
|
+
lfc2 = calc_local_fc_from_pBmat_2(test_hess, bond_pBmat)
|
|
595
|
+
print(lfc, undfc, lndfc, lfc2)
|
|
596
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(test_hess, torsion_pBmat)
|
|
597
|
+
lfc2 = calc_local_fc_from_pBmat_2(test_hess, torsion_pBmat)
|
|
598
|
+
print(lfc, undfc, lndfc, lfc2)
|
|
599
|
+
print("mass-weighted coordinate")
|
|
600
|
+
elem_mass = np.array([[atomic_mass(elem)**(0.5)] for elem in test_element_list], dtype="float64")
|
|
601
|
+
|
|
602
|
+
bond_pBmat = partial_stretch_B_matirx(test_coord * elem_mass, 1, 2)
|
|
603
|
+
bend_pBmat = partial_bend_B_matrix(test_coord * elem_mass, 2, 1, 3)
|
|
604
|
+
torsion_pBmat = partial_torsion_B_matrix(test_coord * elem_mass, 2, 1, 3, 4)
|
|
605
|
+
print(bond_pBmat, bend_pBmat, torsion_pBmat)
|
|
606
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(tmp_test_mw_hess, bend_pBmat)
|
|
607
|
+
lfc2 = calc_local_fc_from_pBmat_2(tmp_test_mw_hess, bend_pBmat)
|
|
608
|
+
lfc3 = calc_local_fc_from_pBmat_3(tmp_test_mw_hess, bend_pBmat)
|
|
609
|
+
print(lfc, undfc, lndfc, lfc2 * 5140.48, lfc3, lfc2)
|
|
610
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(tmp_test_mw_hess, bond_pBmat)
|
|
611
|
+
lfc2 = calc_local_fc_from_pBmat_2(tmp_test_mw_hess, bond_pBmat)
|
|
612
|
+
lfc3 = calc_local_fc_from_pBmat_3(tmp_test_mw_hess, bond_pBmat)
|
|
613
|
+
print(lfc, undfc, lndfc, lfc2 * 5140.48, lfc3, lfc2)
|
|
614
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(tmp_test_mw_hess, torsion_pBmat)
|
|
615
|
+
lfc2 = calc_local_fc_from_pBmat_2(tmp_test_mw_hess, torsion_pBmat)
|
|
616
|
+
lfc3 = calc_local_fc_from_pBmat_3(tmp_test_mw_hess, torsion_pBmat)
|
|
617
|
+
print(lfc, undfc, lndfc, lfc2 * 5140.48, lfc3, lfc2)
|
|
618
|
+
|
|
619
|
+
stack_Bmat = np.vstack([bond_pBmat, bend_pBmat, torsion_pBmat])
|
|
620
|
+
lfc, undfc, lndfc = calc_local_fc_from_pBmat(tmp_test_mw_hess, stack_Bmat)
|
|
621
|
+
lfc2 = calc_local_fc_from_pBmat_2(tmp_test_mw_hess, stack_Bmat)
|
|
622
|
+
lfc3 = calc_local_fc_from_pBmat_3(tmp_test_mw_hess, stack_Bmat)
|
|
623
|
+
print(lfc, undfc, lndfc, lfc3 * 5140.48, lfc2 * 5140.48, lfc3, lfc2)
|
|
624
|
+
|
|
625
|
+
angle_B_matrix_derivative = torch_B_matrix_derivative(torch.tensor(test_coord * elem_mass, dtype=torch.float64), [2, 1, 3], torch_calc_angle)
|
|
626
|
+
angle_B_matrix_derivative = angle_B_matrix_derivative.detach().numpy()
|
|
627
|
+
print(angle_B_matrix_derivative)
|
|
628
|
+
angle_B_matrix = torch_B_matrix(torch.tensor(test_coord * elem_mass, dtype=torch.float64), [2, 1, 3], torch_calc_angle)
|
|
629
|
+
angle_B_matrix = angle_B_matrix.detach().numpy()
|
|
630
|
+
angle_B_matrix = angle_B_matrix.reshape(1, 12)
|
|
631
|
+
print(angle_B_matrix.reshape(1, 12))
|
|
632
|
+
#For test, test_coord is used as gradient.
|
|
633
|
+
int_grad = calc_int_grad_from_pBmat(test_coord.reshape(12, 1), angle_B_matrix)
|
|
634
|
+
cart_grad_from_int_grad = calc_cart_grad_from_pBmat(-int_grad, angle_B_matrix)
|
|
635
|
+
print(((cart_grad_from_int_grad - test_coord.reshape(12, 1))))
|
|
636
|
+
int_hess = calc_int_hess_from_pBmat_for_non_stationary_point(test_hess, angle_B_matrix, angle_B_matrix_derivative, int_grad)
|
|
637
|
+
cart_hess_from_int_hess = calc_cart_hess_from_pBmat_for_non_stationary_point(int_hess, angle_B_matrix, angle_B_matrix_derivative, int_grad)
|
|
638
|
+
print(((cart_hess_from_int_hess - test_hess)))
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def convergence_check(grad, MAX_FORCE_THRESHOLD, RMS_FORCE_THRESHOLD):
|
|
5
|
+
"""Check convergence based on maximum and RMS force thresholds.
|
|
6
|
+
|
|
7
|
+
Parameters
|
|
8
|
+
----------
|
|
9
|
+
grad : numpy.ndarray
|
|
10
|
+
Gradient vector
|
|
11
|
+
MAX_FORCE_THRESHOLD : float
|
|
12
|
+
Maximum force threshold for convergence
|
|
13
|
+
RMS_FORCE_THRESHOLD : float
|
|
14
|
+
RMS force threshold for convergence
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
bool
|
|
19
|
+
True if converged, False otherwise
|
|
20
|
+
"""
|
|
21
|
+
max_force = abs(grad.max())
|
|
22
|
+
rms_force = abs(np.sqrt((grad**2).mean()))
|
|
23
|
+
if max_force < MAX_FORCE_THRESHOLD and rms_force < RMS_FORCE_THRESHOLD:
|
|
24
|
+
return True
|
|
25
|
+
else:
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
|