
{"id":337,"date":"2025-04-06T22:28:21","date_gmt":"2025-04-06T14:28:21","guid":{"rendered":"https:\/\/www.shirui.me\/blog\/?p=337"},"modified":"2026-01-13T12:44:29","modified_gmt":"2026-01-13T04:44:29","slug":"vector-calculus-notes-1","status":"publish","type":"post","link":"https:\/\/www.shirui.me\/blog\/2025\/04\/06\/vector-calculus-notes-1\/","title":{"rendered":"Vector calculus notes (1)"},"content":{"rendered":"\n<p>Problem: given a series molecules $i=1,\\dots,N$, connected with junction atoms $\\mathbf{x}_i^k$, for $k=1,2,&#8230;m$ if there are $m_i$ atoms from molecule $i$ that are bonded with other molecules. The connection bonds are defined as $\\mathbf{b}_i := \\lbrace\\mathbf{x}_j^{k_1}-\\mathbf{x}_i^{k_2}|\\forall k_1, k_2\\, \\mathrm{and}\\, \\forall j\\in \\mathrm{neighbor\\, of}\\, i\\rbrace$, assume that the center-of-mass of the molecules are fixed, but are rotatable, minimize $\\sum_i |\\mathbf{b}_i|^2$ with a series of rotation matrices $R_i$:<\/p>\n\n\n\n<p>$$ R_i = \\min_{R_i}(L:= \\sum_i \\sum_{j \\in \\mathrm{neighbor\\, of}\\, i} \\sum_{k_1,k_2} |\\mathrm{pbc}(R_j \\mathbf{x}_{j}^{k_1} &#8211; R_i \\mathbf{x}_{i}^{k_2})|^2) $$<\/p>\n\n\n\n<p>with constraint<\/p>\n\n\n\n<p>$$ c_1=\\sum_i |R_i^TR_i &#8211; I|^2 = 0 $$<\/p>\n\n\n\n<p>$$ c_2=\\det(R_i) &#8211; 1=0 $$<\/p>\n\n\n\n<p>the constraint ensures $R^T R =I$ and $\\det(R)=1$ for each rotation matrix thus $R_i$ are rotation matrices. The periodic boundary condition is introduced for most simulation systems.<\/p>\n\n\n\n<p>Minimization procedure includes calculation of jacobian of loss and constraint functions:<\/p>\n\n\n\n<p>$$ \\frac{\\partial L}{\\partial R_i} = -2 \\sum_{j \\in \\mathrm{neighbor\\, of}\\, i} \\sum_{k_1, k_2} \\mathrm{pbc}(R_{j} \\mathbf{x}_{j}^{k_1} &#8211; R_i \\mathbf{x}_i^{k_2})^T \\mathbf{x}_i^{k_2} $$<\/p>\n\n\n\n<p>and <\/p>\n\n\n\n<p>$$\\frac{\\partial c_1}{\\partial R_i} = 4 (R_i R_i^T &#8211; I) R_i $$<\/p>\n\n\n\n<p>$$\\frac{\\partial c_2}{\\partial R_i} = \\det(R_i) (R_i^{-1})^T $$<\/p>\n\n\n\n<p>Or the merged constraint (?):<\/p>\n\n\n\n<p>$$ c = \\sum_i |R_i^TR_i &#8211; I|^2 + (\\det (R_i)-1)^2 = 0 $$<\/p>\n\n\n\n<p>with<\/p>\n\n\n\n<p>$$\\frac{\\partial c}{\\partial R_i} = 4 (R_i R_i^T &#8211; I) R_i + 2(\\det(R_i)-1)\\det(R_i)(R_i^{-1})^T $$<\/p>\n\n\n\n<pre class='language-python'><code class='language-python'>def cons_jac(R): # Only the second part\n    R = R.reshape(-1, 3, 3)\n    det = np.linalg.det(R)\n    inv = np.linalg.pinv(R)\n    return 2 * det[:, None, None] * (det[:, None, None] - 1) * np.swapaxes(inv, (1, 2))\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: given a series molecules $i=1,\\dots,N$, connected with junction atoms $\\mathbf{x}_i^k$, for $k=1,2,&#8230;m$ if there are $m_i$ atoms from molecule $i$ that are bonded with other molecules. The connection bonds are defined as $\\mathbf{b}_i := \\lbrace\\mathbf{x}_j^{k_1}-\\mathbf{x}_i^{k_2}|\\forall k_1, k_2\\, \\mathrm{and}\\, \\forall j\\in \\mathrm{neighbor\\, of}\\, i\\rbrace$, assume that the center-of-mass of the molecules are fixed, but are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[16],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-notes","tag-molecular-dynamics"],"_links":{"self":[{"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":23,"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":521,"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/posts\/337\/revisions\/521"}],"wp:attachment":[{"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shirui.me\/blog\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}