-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
262 lines (127 loc) · 231 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>实验室服务器运维记录(1)</title>
<link href="/2024/05/21/lab-server-maintenance-record/"/>
<url>/2024/05/21/lab-server-maintenance-record/</url>
<content type="html"><![CDATA[<p>以下为Tanglab实验室服务器的运维记录,主要记载部分计算化学软件的安装</p><h3 id="Gromacs-2023-with-CUDA"><a href="#Gromacs-2023-with-CUDA" class="headerlink" title="Gromacs 2023 with CUDA"></a>Gromacs 2023 with CUDA</h3><p><a href="http://sobereva.com/457">GROMACS的安装方法(含全程视频演示) - 思想家公社的门口:量子化学·分子模拟·二次元</a></p><p>(2024.02.22) 因原有Gromacs不支持CUDA,现重新编译,之前已手动编译cmake和fftw3310,故直接进入安装部分</p><p>下载gromacs2023.tar.gz,解压至/smb/open-apps,进入解压后的目录,在终端里依次运行</p><pre><code class="lang-bash">mkdir buildcd buildexport CMAKE_PREFIX_PATH=/smb/open-apps/fftw3310cmake .. -DCMAKE_INSTALL_PREFIX=/smb/open-apps/gmx2023 -DGMX_GPU=CUDA -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.8make install -j</code></pre><p>安装完成后,在环境变量中添加</p><pre><code class="lang-bash">source /smb/open-apps/gmx2023/bin/GMXRC</code></pre><p>目前输入gmx运行有反应,等待令屾反馈</p><p>(2024.02.25) 应令屾要求,改装为双精度+MPI版本,以确保模拟大体系时收敛,同时满足跨节点要求,故在原指令基础上进一步改动。值得注意的是,只有单精度版本支持GPU加速,双精度版本不支持!</p><p>FFTW库编译如下(位于安装包目录/smb/open-apps/fftw-3.3.10下):</p><pre><code class="lang-bash">#双精度版本./configure --prefix=/smb/open-apps/fftw3310 --enable-sse2 --enable-avx --enable-sharedmake -jmake install -j#单精度版本./configure --prefix=/smb/open-apps/fftw3310_float --enable-sse2 --enable-avx --enable-float --enable-sharedmake -jmake install -j</code></pre><p>OpenMPI编译如下(位于安装包目录/smb/open-apps/openmpi-5.0.2下):</p><pre><code class="lang-bash">./configure --prefix=/smb/open-apps/openmpi502make -jmake install -j</code></pre><p>安装完成后,在环境变量中添加(此方法已废止,改用environment modules管理,见下文):</p><pre><code class="lang-bash">export PATH=$PATH:/smb/open-apps/openmpi502/binexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/smb/open-apps/openmpi502/lib</code></pre><p>Gromacs编译如下:</p><pre><code class="lang-bash">mkdir buildcd build# 编译单精度,带CUDA GPU加速export CMAKE_PREFIX_PATH=/smb/open-apps/fftw3310_floatcmake .. -DCMAKE_INSTALL_PREFIX=/smb/open-apps/gmx2023 -DGMX_GPU=CUDA -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.8make -jmake install -j# 编译单精度+mpi版本,带CUDA GPU加速export CMAKE_PREFIX_PATH=/smb/open-apps/fftw3310_floatcmake .. -DCMAKE_INSTALL_PREFIX=/smb/open-apps/gmx2023 -DGMX_MPI=ON -DGMX_GPU=CUDA -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.8make -jmake install -j# 编译双精度+mpi版本(上一步编译的是mpi版本,这一步忘记关MPI选项,所以仍编译mpi版本)export CMAKE_PREFIX_PATH=/smb/open-apps/fftw3310cmake .. -DCMAKE_INSTALL_PREFIX=/smb/open-apps/gmx2023 -DGMX_DOUBLE=ON -DGMX_GPU=OFFmake -jmake install -j# 编译双精度版本export CMAKE_PREFIX_PATH=/smb/open-apps/fftw3310cmake .. -DCMAKE_INSTALL_PREFIX=/smb/open-apps/gmx2023 -DGMX_MPI=OFF -DGMX_DOUBLE=ON -DGMX_GPU=OFFmake -jmake install -j</code></pre><p>(2024.02.27) 反馈说gmx_d无法启用thread_mpi,怀疑是-DGMX_MPI=OFF顺带把thread_mpi关掉了,因此重编译如下</p><pre><code class="lang-bash"># located in /smb/open-apps/gromacs2023/build# 编译双精度版本export CMAKE_PREFIX_PATH=/smb/open-apps/fftw3310cmake .. -DCMAKE_INSTALL_PREFIX=/smb/open-apps/gmx2023 -DGMX_MPI=OFF -DGMX_THREAD_MPI=ON -DGMX_DOUBLE=ON -DGMX_GPU=OFFmake -jmake install -j</code></pre><h3 id="环境变量管理器Environment-Modules"><a href="#环境变量管理器Environment-Modules" class="headerlink" title="环境变量管理器Environment Modules"></a>环境变量管理器Environment Modules</h3><p>安装environment modules:</p><pre><code class="lang-bash">sudo apt-get -y install environment-modules</code></pre><p>为自配的OpenMPI 5.0.2配置环境变量,进入/usr/share/modules/modulefiles,以管理员权限创建目录/mpi/openmpi,并在openmpi文件夹下输入以下命令</p><pre><code class="lang-bash"># 创建module文件sudo vim 5.0.2# 在vim界面,按I键启用添加文字,输入下述代码#%Modulesetenv OPAL_PREFIX /smb/open-apps/openmpi502setenv OPAL_LIBDIR /smb/open-apps/openmpi502/libprepend-path PATH /smb/open-apps/openmpi502/binprepend-path LIBRARY_PATH /smb/open-apps/openmpi502/libprepend-path LD_LIBRARY_PATH /smb/open-apps/openmpi502/lib# 按Esc键退出vim增添模式,输入:wq,回车,保存文件# 查看已知modulesmodule avail--------------------/usr/share/modules/modulefiles --------------------dot module-git module-info modules mpi/openmpi/5.0.2 null use.ownKey:loaded modulepath# 启用openmpi环境module load mpi/openmpi/5.0.2# 停用openmpi环境module unload mpi/openmpi/5.0.2</code></pre><h3 id="Wolfram-Mathematica-Wolfram-Engine"><a href="#Wolfram-Mathematica-Wolfram-Engine" class="headerlink" title="Wolfram Mathematica/Wolfram Engine"></a>Wolfram Mathematica/Wolfram Engine</h3><p>下载链接:</p><p><a href="https://www.wolfram.com/engine/">Wolfram Engine</a></p><p>在上述页面选择对应的Linux版本下载,之后注册Wolfram ID,获取免费使用许可证</p><p>将安装包置于/smb/open-apps下,输入sudo bash WolframEngine_14.0.0_LINUX.sh,运行安装程序</p><pre><code class="lang-bash">Wolfram Engine 14.0.0 for LINUX Installer ArchiveVerifying archive integrity. Extracting installer...............------------------------------------------------------------------------ Wolfram Engine 14.0 Installer ------------------------------------------------------------------------Copyright (c) 1988-2023 Wolfram Research, Inc. All rights reserved.WARNING: Wolfram Engine is protected by copyright law and internationaltreaties. Unauthorized reproduction or distribution may result in severecivil and criminal penalties and will be prosecuted to the maximum extentpossible under law.Enter the installation directory, or press Enter to select/smb/open-apps/Wolfram/WolframEngine/14.0:>Type the directory path in which the Wolfram Engine script(s) will be created,or press Enter to select /usr/local/bin:></code></pre><p>用环境变量管理器,在/usr/share/modules/modulefiles下创建目录/wolfram_engine,以及下属文件14.0,内容如下:</p><pre><code class="lang-bash">#%Modulesetenv WolframKernel /smb/open-apps/Wolfram/WolframEngine/14.0/Executables/WolframKernelprepend-path PATH /usr/local/bin</code></pre><p>用module load wolfram_engine/14.0加载环境,输入wolframscript,跳出激活页面</p><pre><code class="lang-bash">The Wolfram Engine requires one-time activation on this computer.Visit https://wolfram.com/engine/free-license to get your free license.Wolfram ID: user@email.comPassword:</code></pre><p>输入刚注册的Wolfram ID和密码即可,不过目前发现每次用module load加载后,运行wolframscript都要激活,暂时没有更好的解决方案</p>]]></content>
<categories>
<category> 网络技术 </category>
</categories>
<tags>
<tag> GROMACS </tag>
<tag> Mathematica </tag>
</tags>
</entry>
<entry>
<title>基于Hexo框架的GitHub个人主页搭建教程(后篇)</title>
<link href="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/"/>
<url>/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/</url>
<content type="html"><![CDATA[<p>(限于篇幅,笔者将搭建教程拆分为两篇。嗯,还记得之前做了什么工作?<a href="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework">回去看看吧</a>)</p><h3 id="Part-IV-做一次大装修,让个人主页更美观"><a href="#Part-IV-做一次大装修,让个人主页更美观" class="headerlink" title="Part IV. 做一次大装修,让个人主页更美观"></a>Part IV. 做一次大装修,让个人主页更美观</h3><p>虽然我们给个人主页套上了色彩鲜艳的Material主题,但细细品味会发觉,我们的主角——博客文章,还没有登场!而博客文章的“好兄弟”——分类、标签、404页面……也不见踪影。另一方面,个人主页的边边角角,也需要我们亲自打理一番,这当中就包括背景和题图。下面,就随着笔者的思路,看一看怎么给个人主页,做一次全方位的大装修吧!</p><h4 id="为GitHub个人主页添加文章"><a href="#为GitHub个人主页添加文章" class="headerlink" title="为GitHub个人主页添加文章"></a>为GitHub个人主页添加文章</h4><p>充实GitHub主页的第一步,自然是添加文章。按照惯例,我们首先到本地的个人主页根目录,右键弹出菜单,点选“Git bash”将其打开,然后输入如下命令,创建一篇新文章:</p><pre><code class="lang-bash">hexo new post "(new_post_title)"</code></pre><p>此处的<code>(new_post_title)</code>指文章的标题,例如创建一篇标题叫“Are you OK?”的文章,就在Git bash输入<code>hexo new post "Are you OK?"</code>,并按下回车。</p><p>这时我们进入source文件夹,会发现生成了一个名为“_posts”的文件夹,点进去一看,里面生成了一个Markdown文件——“Are-you-OK.md”,用于撰写博客文章。如果开启了附件文件夹功能,还会连带生成一个叫“Are-you-OK”的文件夹,用来存放文章插图等附件。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_1.png" style="zoom: 60%;"></center><center><strong>图4.1</strong> 在_post文件夹中新生成的博客文章和附件文件夹(仅用于示例,之后删除)</center><p>打开“Are-you-OK.md”,可以看到文件中写有如下内容:</p><pre><code class="lang-markdown">---title: Are you OK?date: 2022-11-22 09:47:59tags:---</code></pre><p>这是每一个通过<code>hexo new</code>命令创建的Markdown文件,都会自动生成的内容,它包含着标题、创建日期、标签等信息,并可以通过修改scaffold文件夹下的post.md等模板文件,规定每一次创建Markdown文件时写入的内容与格式。<strong>为保证<code>hexo g</code>生成网页代码时,不会因为缺失信息而出错,请务必不要删除文件开头的补充信息,尤其是title和date两行!如果要撰写文章,请务必在补充信息后另起一行,再开始写作!</strong></p><p>剩下的部分,就是用Markdown语言撰写博客文章,事实上,除了几种较为特殊的格式外,大多数情况下,使用Markdown写作与使用Word等软件写作并无二致,并且<strong>在Typora、Notion等Markdown写作软件的帮助下,甚至不需要了解Markdown格式,只要单击右键唤出设置菜单,或是善加利用快捷键,就能完成绝大多数格式的设置。</strong>如果对Markdown语言非常感兴趣,也有<a href="https://www.markdownguide.org/">官方英文教程</a>和<a href="https://www.runoob.com/markdown/md-tutorial.html">菜鸟编程的指南</a>可供参考,而<a href="https://www.cnblogs.com/RioTian/p/14111021.html">Markdown 公式指导手册</a>则进一步介绍如何在Markdown中添加数学公式,这对于提升Markdown水平大有裨益。</p><h4 id="为GitHub个人主页添加分类与标签"><a href="#为GitHub个人主页添加分类与标签" class="headerlink" title="为GitHub个人主页添加分类与标签"></a>为GitHub个人主页添加分类与标签</h4><p>撰写个人博客越久,各类博文积累得越多,不同主题的文章交织在一起,不利于知识点的归纳总结。因此,给现有的博客文章分门别类,也就变得愈发重要。</p><p>在Hexo框架下,分门别类是依靠分类(或称类别,Categories)和标签(Tags)实现的。按照笔者的理解,分类相当于主题,一篇文章只有在大方向上围绕特定概念阐述,才能归属于对应分类;标签相当于关键词,一篇文章只要提及特定概念,就可以加上对应的标签。而要想使用Hexo的分类与标签功能,就必须分别创建分类页与标签页,并在每篇文章的页面信息部分,添加对分类与标签的描述,才能给个人主页的文章添加分类与标签。</p><p>以分类为例,在根目录下打开Git bash,输入<code>hexo new page "categories"</code>并回车,此时会创建一个分类页,其源码地址为<code>/source/categories/index.md</code>,我们打开这个<code>index.md</code>,把页面信息修改为:</p><pre><code class="lang-markdown">---title: categoriesdate: 2022-11-17 15:55:30type: categorieslayout: categories---</code></pre><p>之后保存并退出,转到<code>/source/_posts</code>下的各篇文章,打开后按如下格式添加分类(<strong>注意:应用Material主题后,直接在categories后面空一格写分类,编译时似乎无法识别,一定要换行后空两格,写成<code> - (your_category_name)</code>的形式才能识别</strong>):</p><pre><code class="lang-markdown">---title: ×××categories: - ××××date: 20××-××-×× ××:××:××---</code></pre><p>同理,若输入<code>hexo new page "tags"</code>并回车,此时会创建一个标签页,其源码地址为<code>/source/tags/index.md</code>,仿照前面的做法,我们把<code>index.md</code>的页面信息修改为:</p><pre><code class="lang-markdown">---title: tagsdate: 2022-11-17 15:56:57type: tagslayout: tags---</code></pre><p>此时博客文章的页面信息也要相应修改为(<strong>注意:应用Material主题后,标签同样要写成<code> - (your_category_name)</code>的形式才能识别</strong>):</p><pre><code class="lang-markdown">---title: ×××tags: - ×××× - ××××categories: - ××××date: 20××-××-×× ××:××:××---</code></pre><p>将分类与标签整合在一起,文章的分门别类就做好了,例如本篇文章的页面信息,是这样设定的:</p><pre><code class="lang-markdown">---title: 基于Hexo框架的GitHub个人主页搭建教程(后篇)tags: - GitHub - Hexo - Node.js - Material主题categories: - 网络技术date: 2022-11-20 11:59:30thumbnail: /2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/thumbnail.png---</code></pre><p>可以看到,这里的分类与标签有中文,有英文,还有标点。出于程序员的习惯,笔者不想在编译时生成中文分类与标签(否则在地址栏显示时,会变成乱码,标点符号同理),只想让这些分类与标签,在最终显示的网页界面上以中文表示。对此,Hexo框架也有自己的对策——<code>category_map</code>和<code>tag_map</code>,直译过来就是“分类映射”与“标签映射”。这两者是根目录<code>_config.yml</code>的设置选项,其格式满足:</p><pre><code class="lang-yaml">category_map: category_name1: category_address1 category_name2: category_address2tag_map: tag_name1: tag_address1 tag_name2: tag_address2</code></pre><p>上面的代码中,<code>category_name</code>(或<code>tag_name</code>)代表分类(或标签)在博客文章中的命名,而<code>category_address</code>(或<code>tag_address</code>)代表分类(或标签)在生成网页源码时采用的命名,例如本篇文章的映射是这样设计的:</p><pre><code class="lang-yaml">category_map: 网络技术: networkingtag_map: Node.js: nodejs Material主题: hexo-theme-material</code></pre><p>它们的作用是:把原文页面信息的“网络技术”分类,映射为“networking”,而把“Node.js”及“Material主题”这两个标签,分别映射为“nodejs”和“hexo-theme-material”。经过上述处理后,网页源代码中就不会出现乱码了。</p><p>最后,为了显示分类区与标签云,我们还要在主题文件夹的<code>_config.yml</code>,添加一段创建分类区与标签云的代码,具体而言,找到<code>sidebar:</code>对应的代码块,里面有一个选项叫<code>pages:</code>,其默认设置为:</p><pre><code class="lang-yaml"># Sidebar Customizesidebar: ...... categories: use: false icon: chrome_reader_mode divider: false pages: #About: #link: "/about" #icon: person #divider: false ......</code></pre><p>将其更改为如下代码并保存:</p><pre><code class="lang-yaml"># Sidebar Customizesidebar: ...... categories: use: true links: "/categories" icon: chrome_reader_mode divider: false pages: #About: #link: "/about" #icon: person #divider: false tags: link: "/tags" icon: cloud_circle divider: false ......</code></pre><p>我们将修改后的个人网页重新生成,得到的就是含有若干文章,且注有分类与标签的个人网页了,如图4.2与图4.3所示。值得注意的是,Material主题默认不采用分类页,而是把分类移动到侧边栏的折叠选项中,因此直接打开分类页,是看不到原来的分类的。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_2.png" style="zoom: 40%;"></center><center><strong>图4.2</strong> Material主题的分类区(被收纳进侧边栏了)</center><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_3.png" style="zoom: 40%;"></center><center><strong>图4.3</strong> Material主题的标签页(原谅我壁纸色调过深,看不到标签了,悲)</center><h4 id="为GitHub个人主页添加自定义404页面"><a href="#为GitHub个人主页添加自定义404页面" class="headerlink" title="为GitHub个人主页添加自定义404页面"></a>为GitHub个人主页添加自定义404页面</h4><blockquote><p>404, can’t live with them, can’t live without them.<br>——反正不是我说的</p></blockquote><p>如果让擅长“面向谷歌/百度编程”的程序员,提名“互联网最令人爱恨交加的东西”,404页面应该“榜上有名”。诚然,404页面弹出的那一瞬间,真的会令程序员崩溃——这意味着找到解决方案的希望再一次破灭了,但从另一角度分析,404界面也意味着,至少访问的页面(可能)曾经存在过,可以尝试用<a href="https://archive.org/web/">Wayback Machine</a>追查历史快照,这何尝不是一种善意的提醒呢?而如果此时的404页面,显示的并不是简简单单的“404 Not Found”几个大字,而是幽默风趣的笑话,有意思的图片,甚至是一个小游戏,那么沮丧的心情,是不是也会感到些许轻松愉悦。</p><p>可惜的是,许多人搭建的GitHub个人主页,都没有设置自定义404页面,以至于每次我打开失效的个人主页链接,跳出来的都是这样一个玩意:</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_4.png" style="zoom: 40%;"></center><center><strong>图4.4</strong> GitHub的默认404页面(<del>噔 噔 咚</del>)</center><p>这跟你们的个人主页的画风根本不搭啊!个人主页再怎么简陋,也得做一个基于本站框架的404页面吧!(路人:谁知道Hexo框架可以自定义404页面嘛?!)</p><p>当然,Hexo框架早就为大家准备了解决方案:在根目录下打开Git bash,输入<code>hexo new page "404"</code>并回车,就可以创建一个404页面,它的源码地址为<code>/source/404/index.md</code>,我们只要打开这个<code>index.md</code>,把页面信息修改为:</p><pre><code class="lang-markdown">title: 404 Not Founddate: 2022-11-20 13:03:13comments: falsepermalink: /404.html</code></pre><p>其余部分就可以自由发挥啦!例如笔者的个人主页,使用的404页面是这样的:</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_5.png" style="zoom: 40%;"></center><center><strong>图4.5</strong> 自定义404页面效果图(此处埋了个彩蛋,见<a href="/404.html">本站404页面</a>)</center><h4 id="为GitHub个人主页更换背景壁纸"><a href="#为GitHub个人主页更换背景壁纸" class="headerlink" title="为GitHub个人主页更换背景壁纸"></a>为GitHub个人主页更换背景壁纸</h4><p>不知诸位是否稍加留意过<a href="https://iblh.github.io/material-demo/">Material主题的展示页</a>?细心的吃瓜群众会发现,这个展示页每篇文章的题图是色彩斑斓的,开启后的侧边栏也是色彩斑斓的,唯独背景,是一大块纯纯的灰白色!这不禁让人疑惑:为什么色彩斑斓的Material主题,宁肯用单色填充网页背景,也不愿意换上一张类似于题图风格的壁纸?其实,Material主题确实存有预设的背景壁纸,只是由于默认参数中没有启用背景壁纸,所以生成的网页自然都采用单色背景。</p><p>那么,怎样才能启用壁纸功能呢?很简单,打开主题包文件夹<code>themes/hexo-theme-material</code>下的<code>_config.yml</code>,定位到“background”附近,此时会看到如下代码:</p><pre><code class="lang-yaml">background: purecolor: "#F5F5F5" #bgimg: "/img/bg.png" bing: enable: false parameter:</code></pre><p>如果要启用壁纸功能,就在<code>purecolor: "#F5F5F5"</code>前面加上一个“#”,并将<code>#bgimg: "/img/bg.png"</code>中的“#”删除,之后重新编译网页源码,就能在本地网页看到预设的背景壁纸。</p><p>等等,默认壁纸的地址为<code>/img/bg.png</code>,那这是否意味着,我们不但能启用壁纸,还能将Material预设的背景壁纸,更换为自定义壁纸?没错!在<code>themes/hexo-theme-material/source/img</code>下,确实存放着网页背景壁纸、网站logo、按钮图标等图片素材,我们只要把喜欢的背景壁纸,更名为<code>bg_new.png</code>(便于与原有的<code>bg.png</code>区别),然后拷贝到<code>themes/hexo-theme-material/source/img</code>当中,如图4.3所示:</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_6.png" style="zoom: 40%;"></center><center><strong>图4.6</strong> 将自定义壁纸拷贝到默认壁纸所在的文件夹</center><p>之后编辑主题文件夹的<code>_config.yml</code>,将“background”改为</p><pre><code class="lang-yaml">background: #purecolor: "#F5F5F5" bgimg: "/img/bg_new.png" bing: enable: false parameter:</code></pre><p>重新编译网页源码,原来的单色背景就被替换成自己喜欢的背景壁纸了,好耶!</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_7.png" style="zoom: 40%;"></center><center><strong>图4.7</strong> 替换壁纸后的效果图(此处已更换题图,方法见下一部分)</center><h4 id="为你的文章更换题图"><a href="#为你的文章更换题图" class="headerlink" title="为你的文章更换题图"></a>为你的文章更换题图</h4><p>在<a href="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/">上一篇教程</a>中,笔者曾提及,Material主题会为每一篇文章加上一张随机选取的题图。对于疏于装饰的博主们而言,Material自带的题图足以让人眼前一亮,但对于喜欢妆点主页的博主而言,Material自带的题图显然并不能满足自己的口味。这时候,启用Hexo的<strong>资源文件夹</strong>(asset folder,笔者更喜欢叫附件文件夹),就可以把随机选取的预设题图,换成萌萌哒的小姐姐,这样工作效率就能达到一万三千点呢(笑)。</p><p><strong>资源文件夹</strong>的启用方法很简单,只要在根目录的<code>_config.yml</code>中,找到<code>post_asset_folder:</code>这一选项,将其更改为</p><pre><code class="lang-yaml">post_asset_folder: true</code></pre><p>今后用<code>hexo new post (...)</code>创建新文章时,就会在存储文章的同一目录下,生成同名的资源文件夹,这是不是很方便呢?当然,已有的老文章,也可以通过在同一目录下,直接创建与其同名的空文件夹,从而达到生成资源文件夹的目的。</p><p>成功启用资源文件夹后,剩下的事情易如反掌:打开想要更换题图的文章,在其页面信息部分,添加一行与题图有关的信息,其中article_year、article_month、article_day、article_name,分别对应于文章创建的年、月、日,以及存储文章的Markdown文件名:</p><pre><code class="lang-markdown">thumbnail: /(article_year)/(article_month)/(article_day)/(article_name)/thumbnail.png</code></pre><p>接下来,进入与文章同名的资源文件夹,把裁剪后的题图(建议高宽比为7: 22)复制到该文件夹中,并重命名为thumbnail.png(或其他图片格式),之后重新编译网页源码,就能看到替换的题图啦!</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_8.png" style="zoom: 40%;"></center><center><strong>图4.8</strong> 更换题图后,本篇文章在首页的样式</center><p>事实上,Hexo的<strong>资源文件夹</strong>还有许多用途:不仅能存放题图,还能<strong>存放文章中使用的插图</strong>,极大省去额外借用或搭设图床的麻烦;不仅能存放图片,还能<strong>存放可视化图表、音乐、视频等</strong>,并能借助第三方插件进行调用,<strong>实现复杂的展示效果</strong>。对于大多数博主而言,这里最重要的功能是插入配图,而基于Markdown格式的便捷调用方式,则会在Part V中详细阐述,此处按下不表。</p><h4 id="实装代码高亮功能"><a href="#实装代码高亮功能" class="headerlink" title="实装代码高亮功能"></a>实装代码高亮功能</h4><p>原生Hexo的代码高亮插件似乎存在问题,无法识别bash等编程语言,致使这些语言的代码块全部不显示高亮。好在Material主题提供了两种代码高亮插件prettify和hanabi,它们都能正常识别大部分主流编程语言,并根据语言种类正确渲染。这里我们采用prettify,实现GitHub个人主页的代码高亮功能。</p><p>首先,为防止原生Hexo的代码高亮插件和prettify同时运行,造成行号重复出现等错误,我们要打开根目录下的<code>_config.yml</code>,找到“highlight”部分:</p><pre><code class="lang-yaml">highlight: enable: true line_number: true auto_detect: false tab_replace: '' wrap: true hljs: false</code></pre><p>将其中的“enable”和“line_number”选项均改成“false”,保存修改。之后打开主题文件夹下的<code>_config.yml</code>,查找并定位“prettify”或“hanabi”,得到下列代码段:</p><pre><code class="lang-yaml"># Code highlight# You can only enable one of them to avoid issues.# Also you need to disable highlight option in hexo's _config.yml.## Prettify# theme: # Available value in /source/css/prettify/[theme].min.cssprettify: enable: false theme: "github-v2"# Hanabi (https://github.com/egoist/hanabi)# line_number: [true/false] # Show line number for code block# includeDefaultColors: [true/false] # Use default hanabi colors# customColors: This value accept a string or am array to setting for hanabi colors.# - If `includeDefaultColors` is true, this will append colors to the color pool# - If `includeDefaultColors` is false, this will instead default color poolhanabi: enable: false line_number: true includeDefaultColors: true customColors:</code></pre><p>将“prettify”下属的“enable”选项改成“true”,保存修改,此时prettify插件已经启用。在根目录下打开Git bash,输入<code>hexo clean && hexo g</code>,重新生成本地网页,然后输入<code>hexo s</code>,就可以在本地服务器上,看到prettify渲染后的代码块。</p><p>如果对默认的“github-v2”格式不太满意,可以到<code>\themes\hexo-theme-material\source\css\prettify</code>下,查看prettify支持的代码渲染格式,它们的渲染效果参见<a href="https://jmblog.github.io/color-themes-for-google-code-prettify/">Color themes for Google Code Prettify</a>。之后,回到主题文件夹下的<code>_config.yml</code>,往prettify下属选项theme后面的双引号内,填入喜欢使用的代码渲染格式,例如笔者喜欢“Tomorrow Night Bright”主题,就将theme选项那一行改为<code>theme: "tomorrow-night-bright"</code>并保存,之后生成本地网页,所有的代码块的主题就都变成“Tomorrow Night Bright”,如下图所示:</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig4_9.png" style="zoom: 40%;"></center><center><strong>图4.9</strong> prettify插件采用“Tomorrow Night Bright”主题的渲染效果</center><h3 id="Part-V-部分实用插件的安装与配置"><a href="#Part-V-部分实用插件的安装与配置" class="headerlink" title="Part V. 部分实用插件的安装与配置"></a>Part V. 部分实用插件的安装与配置</h3><h4 id="数学公式插件:hexo-renderer-mathjax"><a href="#数学公式插件:hexo-renderer-mathjax" class="headerlink" title="数学公式插件:hexo-renderer-mathjax"></a>数学公式插件:hexo-renderer-mathjax</h4><p>身为一个化学搬砖工,有时也不可避免跟数学公式打交道,虽然Markdown支持以LaTeX格式书写数学公式,但是个人主页采用的Hexo框架,却没有自带渲染数学公式的插件,也就不能将LaTeX格式的数学公式,转换为便于阅读的印刷体。幸好,通过安装第三方开发的MathJax插件,原生Hexo博客上无法显示的LaTeX形式的数学公式,也能得到正确的解析与渲染,妈妈再也不用担心博客写不出公式了(笑)。</p><p>在启用第三方MathJax插件前,我们首先要把默认的文字渲染引擎<code>hexo-renderer-marked</code>,更换为加强版的<code>hexo-renderer-kramed</code>,这是因为<code>marked</code>没有对MathJax的支持。为此,我们在根目录启用Git bash,输入以下命令:</p><pre><code class="lang-bash">npm uninstall hexo-renderer-marked --savenpm install hexo-renderer-kramed --save</code></pre><p>下一步是修改<code>hexo-renderer-kramed</code>的渲染代码,它位于<code>node_modules/hexo-renderer-kramed/lib/renderer.js</code>。找到下列代码:</p><pre><code class="lang-javascript">// Change inline math rulefunction formatText(text) { // Fit kramed's rule: $$ + \1 + $$ return text.replace(/`\$(.*?)\$`/g, '$$$$$1$$$$');}</code></pre><p>将其改为</p><pre><code class="lang-javascript">// Change inline math rulefunction formatText(text) { return text;}</code></pre><p>这是因为在<code>kramed</code>下,行内公式的插入形式为<code>`$(math_equation)$`</code>,而Markdown行内公式的插入形式为<code>$(math_equation)$</code>,为符合Markdown的使用习惯,只能将formatText的返回值改为<code>text</code>。</p><p>第三步,才是安装第三方MathJax插件,在此之前,为避免可能发生的插件冲突,我们要彻底卸载Hexo原生的数学插件。在根目录打开Git bash,运行下列命令,卸载<code>hexo-math</code>:</p><pre><code class="lang-bash">npm uninstall hexo-math --save</code></pre><p>然后执行下列安装命令,这里我们选用<code>hexo-renderer-mathjax</code>:</p><pre><code class="lang-bash">npm install hexo-renderer-mathjax --save</code></pre><p>从个人主页的根目录下,找到其下的<code>/node_modules/hexo-renderer-mathjax/mathjax.html</code>,用记事本或VSCode打开,定位到最后一行(其格式为<code><script src="..."></script></code>),将其替换为</p><pre><code class="lang-html"><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script></code></pre><p>到这一步,MathJax的配置大致完成,之后是针对Markdown书写格式兼容性的修改,以及MathJax的全局启用。从个人主页的根目录下,转到<code>node_modules/kramed/lib/rules/inline.js</code>,根据<code>var inline = {...}</code>定位代码块,其大致分布在第10-28行。我们将原有的escape和em选项注释掉,它们的形态大致为</p><pre><code class="lang-javascript">escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,</code></pre><p>并在对应行后面另起一行,填入新的escape和em选项,确认无误后保存。这样,Kramed的转义规则就不会把_和^转义为<code><em></code>。</p><pre><code class="lang-javascript">escape: /\\([`*\[\]()# +\-.!_>])/,em: /\*((?:\*\*|[\s\S])+?)\*(?!\*)/,</code></pre><p>最后,回到根目录的<code>_config.yml</code>,在末尾添加如下代码并保存,之后重新编译网页,就能让个人网页正确渲染Markdown公式了。</p><pre><code class="lang-yaml">mathjax: enable: true</code></pre><h4 id="以Markdown格式添加插图与站内超链接:hexo-asset-link"><a href="#以Markdown格式添加插图与站内超链接:hexo-asset-link" class="headerlink" title="以Markdown格式添加插图与站内超链接:hexo-asset-link"></a>以Markdown格式添加插图与站内超链接:hexo-asset-link</h4><p>众所周知,<a href="https://hexo.io/zh-cn/docs/asset-folders">原生的Hexo不支持以Markdown语法格式,结合相对路径插入图片</a>,因为这可能会导致它们在存档页或者主页上显示不正确。如果执意要以相对路径的形式,在原生Hexo博客中添加插图或超链接,就必须要编写成如下形式:</p><pre><code class="lang-markdown">{% asset_path /.../... This is an example path %}{% asset_img example.jpg This is an example image %}{% asset_link https://.../... This is an example path %}</code></pre><p>而Markdown结合相对路径添加添加插图或超链接,则可以写成如下格式:</p><pre><code class="lang-markdown">[This is an example path](/.../...)[This is an example image](example.jpg)[This is an example path](https://.../...)</code></pre><p>可以看到,原生Hexo格式,很难一眼分辨出哪部分是图片(或超链接地址),哪部分是文字说明,并且还要额外指定插入的是何种类型的附件;相比之下,Markdown格式把文字说明和附件地址,分别放在了中括号和小括号,并且不需要指定附件类型。两相比较,高下一目了然——自然是Markdown格式更胜一筹。</p><p>目前,许多开发者已经开发出Hexo原生格式到Markdown格式的转化插件,其中常用的有hexo-asset-link,它的安装方法很简单,只需在根目录运行如下命令即可:</p><pre><code class="lang-bash">npm install -s hexo-asset-link</code></pre><p>安装后,确保根目录<code>_config.yml</code>中,<code>post_asset_folder:</code>选项为true,且_posts同时存有博客文章和同名资源文件夹,就能往GitHub个人主页添加插图。例如以Markdown格式插入example.jpg,就将example.jpg拷贝至资源文件夹,然后打开对应的博客文章,在指定位置写下<code>[This is an example image](example.jpg)</code>。</p><p>又如,要想插入站内链接,就往博客文章中写下</p><pre><code class="lang-markdown">[This is an example path](/(article_year)/(article_month)/(article_day)/(article_name))</code></pre><p>之后重新编译网页,就能在博客内显示相应的站内链接。</p><h4 id="让站内搜索帮你找文章:hexo-generator-search"><a href="#让站内搜索帮你找文章:hexo-generator-search" class="headerlink" title="让站内搜索帮你找文章:hexo-generator-search"></a>让站内搜索帮你找文章:hexo-generator-search</h4><p>相信诸位都会有这样的经历:明明记得在某个网站上看到一篇非常实用的文章,结果因为忘记收藏,下次再想调取时,只能凭着记忆一篇篇翻阅,可谓是劳力又劳心。而即将介绍的站内搜索插件,便能将这样的苦恼一扫而空!</p><p>安装方法也非常简单,首先到个人主页的根目录,打开Git bash,输入如下命令,安装hexo-generator-search:</p><pre><code class="lang-bash">npm install hexo-generator-search --save</code></pre><p>然后进入<code>/theme/(your_material_theme_name)</code>(笔者的路径为<code>/theme/hexo-theme-material</code>),用记事本(或VSCode)打开其下的_config.yml,找到第276-278行附近的位置(或者搜索“search”也能找到),会有这样一段代码:</p><pre><code class="lang-yaml">search: use: google swiftype_key:</code></pre><p>将<code>use: google</code>改成<code>use: local</code>,其他选项不变,然后保存。</p><p>接下来回到个人主页的根目录,用记事本(或VSCode)打开此处的_config.yml,在文件末尾补上如下语句,然后保存:</p><pre><code class="lang-yaml">search: path: search.xml field: all</code></pre><p>最后在根目录打开Git bash,输入<code>hexo clean && hexo g</code>,重新生成网页源码,然后用<code>hexo s</code>启动本地服务器,就能在<a href="http://localhost:4000">http://localhost:4000</a>试用站内搜索功能啦!</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig5_1.png" style="zoom: 60%;"></center><center><strong>图5.1</strong> 站内搜索插件实装效果</center><h3 id="Part-VI-将本地生成的个人主页部署到GitHub"><a href="#Part-VI-将本地生成的个人主页部署到GitHub" class="headerlink" title="Part VI. 将本地生成的个人主页部署到GitHub"></a>Part VI. 将本地生成的个人主页部署到GitHub</h3><p>经过前几部分的努力,我们终于在本地上,把简陋的初始页面打扮得焕然一新,现在,我们只要把本地生成的个人主页,上传到GitHub对应的代码仓库,就可以看到更新后的GitHub个人主页了!考虑到GitHub在国内日常崩坏的连接质量,笔者分别介绍两种部署方法,保证无论身处何地,更新永不缺席!</p><h4 id="流传于网络的部署方法:Hexo直接部署"><a href="#流传于网络的部署方法:Hexo直接部署" class="headerlink" title="流传于网络的部署方法:Hexo直接部署"></a>流传于网络的部署方法:Hexo直接部署</h4><p>Hexo直接部署,可谓是流传最广的部署方法,你在网络上搜索到的基于Hexo框架的GitHub个人主页搭建教程,百分之九十以上都会推荐使用Hexo自带的部署功能,实现GitHub个人主页的更新。此法无需下载额外的软件,只需打开根目录下的_config.yml,找到末尾的deploy部分:</p><pre><code class="lang-yaml">deploy: type:</code></pre><p>将其改为如下内容并保存(<code>(your_username)</code>代表GitHub用户名,<code>(your_sitename)</code>代表创建GitHub主页时使用的用户名,一般等于<code>(your_username)</code>)</p><pre><code class="lang-yaml">deploy: type: repository: git@github.com:(your_username)/(your_sitename).github.io.git branch: master</code></pre><p>然后,在本地个人主页的根目录打开Git bash,先运行<code>hexo g & hexo s</code>,并访问<a href="http://localhost:4000">http://localhost:4000</a>,以确认生成的网页外观与内容符合自己的预期。接着,按下Cltr+C,终止本地服务器预览,随后输入<code>hexo d</code>,回车运行,本地Git便会把生成的网页源码,推送到GitHub个人主页对应的代码仓库。待部署成功后,等待几分钟,就可以访问<code>https://(your_sitename).github.io</code>,欣赏一下更新后的GitHub个人主页啦!</p><p>看起来一切都很美好,但是,实际操作中,往往会出现部署不上去的尴尬情景:</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_1.png" style="zoom: 75%;"></center><center><strong>图6.1</strong> 世界名画:动啊,Git,你为什么不动!</center><p>而且用<code>hexo d</code>命令部署时,我还开着代理服务器!为什么本地的Git还是认为无法与GitHub服务器建立连接!</p><p>于是,我遍历Stackoverflow、CSDN等计算机技术论坛,又问了身边懂服务器运维的同学,结合之前更新课题组网站(那时课题组主页还是用Hugo搭建)的经验,终于鼓捣出“逃课手法”——</p><h4 id="饱受忽略的“旁门左道”:分支合并部署"><a href="#饱受忽略的“旁门左道”:分支合并部署" class="headerlink" title="饱受忽略的“旁门左道”:分支合并部署"></a>饱受忽略的“旁门左道”:分支合并部署</h4><p>这里又会有吃瓜群众不解了:你用Hexo直接部署,实际上利用了本地Git的推送功能;你为GitHub主页的代码仓库建立一个分支,然后把本地源码上传到分支仓库,最后把分支仓库合并到主干仓库,同样用到本地Git的推送功能。既然Hexo直接部署无法上传,凭什么把代码上传到分支仓库就可以呢?别急,容我推荐一款救急神器——GitHub Desktop!</p><p>首先,我们到<a href="https://desktop.github.com/">GitHub Desktop官网</a>,点击中间的紫色按钮,下载64位Windows版GitHub Desktop。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_2.png" style="zoom: 40%;"></center><center><strong>图6.2</strong> GitHub Desktop官网首页</center><p>双击安装包,勾选用户协议,然后保持默认选项不变,一路点选“下一步”,完成安装。</p><p>之后启动GitHub Desktop,此时它会弹出登录界面,提示你输入GitHub账号和密码。我们按照指示,依次填写创建GitHub个人主页所使用的账号与密码,点击“Sign in”登录,此时GitHub会往注册邮箱发送含有六位验证码的邮件,并提示我们填入正确的验证码,我们只需打开邮箱,将验证邮件附带的验证码复制过来,就可以完成登录。</p><p>登录后的GitHub Desktop界面如图6.3所示,除菜单栏外,可分为如下几个部分:</p><p>(1)<strong>地址栏与状态栏</strong>,它们位于窗口正上方,其中地址栏用于显示和切换需要更改的代码仓库与分支,而状态栏则表示本地的代码仓库是否与远程的GitHub仓库同步;</p><p>(2)<strong>修改记录区</strong>,它位于窗口左侧,会标注出本地的代码仓库中哪些文件进行了修改,哪些文件被添加,哪些文件被移除;</p><p>(3)<strong>提交总结与描述区</strong>,当本地的代码仓库中有文件修改或增删,而持有者想要把上述变动应用到远程的GitHub仓库时,就要在这个区域写下提交代码的总结,以及本次提交的代码相较于前一版本的代码有何异同;</p><p>(4)<strong>工作区</strong>,它占据着窗口的大部分,会显示修改记录区中选中的文件,是在具体的哪个区域发生了变动,变动前后的内容又是什么。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_3.png" style="zoom: 40%;"></center><center><strong>图6.3</strong> 登陆后的GitHub Desktop界面</center><p>我们把光标移到菜单栏中的“File”,找到“Clone repository”选项并单击,以打开爬取代码仓库的窗口。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_4.png" style="zoom: 40%;"></center><center><strong>图6.4</strong> 从菜单栏找到下载代码的按钮</center><p>接着选取名字为<code>(your_username).github.io</code>的仓库(更准确说是<code>(your_sitename).github.io</code>,配图图注懒得改了),然后在“Local path”的空白框中,填上希望储存的地址,点击“Clone”,GitHub Desktop就会把远程仓库的代码,下载到指定的本地地址。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_5.png" style="zoom: 40%;"></center><center><strong>图6.5</strong> 把个人网页对应的远程GitHub仓库下载到本地</center><p><strong>之后的重头戏来了:</strong>点击地址栏中的“Current branch”,会弹出显示所有分支的下拉菜单,点击其中的“New branch”按钮,以打开创建新分支的窗口。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_6.png" style="zoom: 40%;"></center><center><strong>图6.6</strong> 从地址栏找到创建新分支的按钮</center><p>然后填写新分支的名字(<strong>注意:</strong>不能与主干仓库master,以及其他已有分支仓库撞名,例如图6.7中,该仓库已经有一条名为“direct_push_branch”的分支,那么继续创建新分支时,就不能叫“direct_push_branch”),点击“Create branch”,在GitHub上生成分支仓库。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_7.png" style="zoom: 40%;"></center><center><strong>图6.7</strong> 为GitHub仓库创建新分支</center><p>接下来,到本地的个人主页根目录打开Git bash,输入<code>hexo clean && hexo g</code>,重新生成源代码,然后打开根目录下的“public”文件夹,将其下的所有文件与文件夹,拷贝到刚刚下载到本地的GitHub仓库中,此时GitHub Desktop会显示添加的文件名称,以及每个文件增添的内容。我们到左下角填写提交总结与提交描述,点击“Commit to (your_branch_name)”,GitHub Desktop便会向远程的GitHub仓库发出提交申请。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_8.png" style="zoom: 40%;"></center><center><strong>图6.8</strong> 确保源码拷贝至新分支的本地仓库后,填写提交总结与提交描述,然后提交</center><p>提交申请后,GitHub Desktop的工作区就会变回默认形态,只是多了一个名为“Push commits to the origin remote”的提示框,要求你把刚才提交的源代码,上传到GitHub仓库对应的分支上,我们只需按照要求,点下蓝色的“Push origin”按钮即可,GitHub Desktop会自动帮我们完成上传的工作。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_9.png" style="zoom: 40%;"></center><center><strong>图6.9</strong> 将提交的代码上传到GitHub对应的分支上</center><p>上传源码后,GitHub Desktop又会弹出一个叫“Create a Pull Request from your current branch”的提示框,要求你把分支仓库的代码,全部合并到主干仓库中(分支仓库的代码依然存在,且保持不变),我们仍旧照做,点下蓝色的“Create Pull Request”按钮。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_10.png" style="zoom: 40%;"></center><center><strong>图6.10</strong> 发起分支仓库到主干仓库的合并</center><p>这时GitHub Desktop不会在软件中处理合并代码的事务,而是用浏览器直接打开GitHub,并弹出类似于图6.11的Pull Request界面(<strong>所以说为什么Pull Request功能没有整合到GitHub Desktop里面?!</strong>),我们再次点下“Create pull request”,让合并工作得以进行。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_11.png" style="zoom: 40%;"></center><center><strong>图6.11</strong> 到跳转的网页版GitHub中,发起分支仓库到主干仓库的合并</center><p>此时GitHub网页会发生一次跳转,如果弹出的提示框说“This branch has no conflicts with the base branch”,即分支仓库与主干仓库没有文件版本的冲突,就可以放心地点击“Merge pull request”,完成合并的最后一步。</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_12.png" style="zoom: 40%;"></center><center><strong>图6.12</strong> 检查分支仓库与主干仓库无冲突后,确认合并</center><p>等到GitHub网页弹出“Pull request successfully merged and closed”的提示框,就意味着部署工作大功告成了!等待几分钟,再访问<code>https://(your_sitename).github.io</code>,你的GitHub个人主页就应该发生翻天覆地的变化啦!</p><center class="half"><img src="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel/creating_GitHub_pages_fig6_13.png" style="zoom: 40%;"></center><center><strong>图6.13</strong> 大功告成!累死我了!</center><p>根据笔者的测试,在同样挂着代理服务器的情况下,用hexo d直接部署,会一直弹出无法访问远程仓库的错误,而用GitHub Desktop结合分支仓库部署,则能正常推送源码,完成整个个人网页的更新。笔者推测,可能是因为GitHub Desktop能根据代理服务器的启用情况,自动适配网络和端口设置,而直接运行hexo d时,由于本地Git服务不会对代理服务器进行任何配置(需要手动调整),因此代理服务器并不能帮助Git与GitHub之间建立稳定的传输连接,这才是分支合并部署得以实现的主要原因。</p><h4 id="后记——关于我费尽九牛二虎之力,却发现自己绕了大远路这件事"><a href="#后记——关于我费尽九牛二虎之力,却发现自己绕了大远路这件事" class="headerlink" title="后记——关于我费尽九牛二虎之力,却发现自己绕了大远路这件事"></a>后记——关于我费尽九牛二虎之力,却发现自己绕了大远路这件事</h4><p>昨天写完GitHub主页搭建教程,发给课题组懂服务器运维的同学审阅,原以为自己的教程应该没啥大问题,直到——</p><p>意达:你后半篇教程中,关于部署的讲解有点问题哈。</p><p>笔者:啥问题呢?我读了一遍下来,也没什么错误啊?</p><p>意达:你不觉得,既然你都能在GitHub Desktop创建远程分支,并且把本地网页的代码推送到远程分支中,那么,为什么不把本地网页的代码,直接推送到主干仓库呢?你这样做不是多此一举嘛?</p><p>笔者:可是我担心,如果直接把源码推送到主干仓库,万一本地源码有点闪失,岂不是容易把GitHub个人主页搞崩?传到分支仓库去,好歹合并时会检查主干与分支是否有冲突。</p><p>意达:但是你的网页只有你自己一个人编写,最后得到的主干版本,跟分支版本没有任何区别。而且,你提交源码的时候,肯定会在本地服务器上预览过至少一遍,才敢提交的吧?如果这时还有错误,那么提交到分支仓库,再合并到主干仓库中,也不会解决任何问题。</p><p>笔者:那万一我的博客需要其他人编辑,又怕其他人乱搞,该怎么办呢?开个分支出来,不是更安全嘛?</p><p>意达:我一般是直接给所有编辑者开放网站仓库的编辑权限的。</p><p>笔者:……行吧,你就当我是在练习分支仓库的使用吧。</p><p>意达:你开心就好。</p><h3 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h3><p><strong>Part IV:</strong></p><p><a href="https://easyhexo.com/2-Theme-use-and-config/2-5-hexo-theme-material/">hexo-theme-material | Easy Hexo</a></p><p><a href="https://www.markdownguide.org/">Markdown Guide</a></p><p><a href="https://www.runoob.com/markdown/md-tutorial.html">Markdown 教程 | 菜鸟编程</a></p><p><a href="https://www.cnblogs.com/RioTian/p/14111021.html">Markdown 公式指导手册</a></p><p><a href="https://www.zhihu.com/question/29017171">hexo 下的分类和表签无法显示,怎么解决?</a></p><p><a href="https://www.zhihu.com/question/21650209">hexo 怎么创建 404 页面?</a></p><p><a href="https://zhangjichengcc.github.io/blog/2018/02/27/hexo-%E5%88%9B%E5%BB%BA%E6%96%87%E7%AB%A0/">hexo 创建文章 & 文章缩略图及banner & MarkDown</a></p><p><strong>Part V:</strong></p><p><a href="https://moonglade.top/2022/02/26/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/hexo-material%E9%85%8D%E7%BD%AE%E4%BF%AE%E6%94%B9%E8%AE%B0%E5%BD%95/index.html">hexo&material配置修改记录</a></p><p><a href="https://www.jianshu.com/p/e8d433a2c5b7">如何在 hexo 中支持 Mathjax?</a></p><p><a href="https://github.com/iblh/hexo-theme-material/issues/743">请问,这个主题如何指定文章的封面图片呢和放大博客文章中的图片? (Issue #743)</a></p><p><a href="https://easyhexo.com/2-Theme-use-and-config/2-5-hexo-theme-material/">hexo-theme-material | Easy Hexo</a></p><p><a href="https://www.programmerall.com/article/95331088559/">Use the Material theme for Hexo</a></p><p><strong>Part VI:</strong></p><p><a href="https://zhuanlan.zhihu.com/p/370635512">超详细 Hexo + Github Pages 博客搭建教程</a></p><p><a href="https://zhuanlan.zhihu.com/p/111614119">(一)Github + Hexo 搭建个人博客超详细教程</a></p><p><a href="https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/overview/getting-started-with-github-desktop">Getting Started with GitHub Desktop</a></p>]]></content>
<categories>
<category> 网络技术 </category>
</categories>
<tags>
<tag> GitHub </tag>
<tag> Hexo </tag>
<tag> Node.js </tag>
<tag> Material主题 </tag>
</tags>
</entry>
<entry>
<title>搭建GitHub主页的常见问题</title>
<link href="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/"/>
<url>/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/</url>
<content type="html"><![CDATA[<p>笔者在亲手搭建GitHub主页时,时常遇到一些奇怪的故障,这些故障或是由插件或网页主题的代码错误引起,或是由于不可言说的网络问题所致,现将目前为止遇到的较为棘手的故障,以及对应的解决方案,一并汇总在这篇文章中,供以后采用Hexo搭建博客时参考。</p><h3 id="GitHub部分"><a href="#GitHub部分" class="headerlink" title="GitHub部分"></a>GitHub部分</h3><h4 id="1-hexo-d部署时一直出现“Connection-reset”或“Connection-redirected-”,之后弹出“Spawn-failed”错误,导致生成的网页一直部署不上去"><a href="#1-hexo-d部署时一直出现“Connection-reset”或“Connection-redirected-”,之后弹出“Spawn-failed”错误,导致生成的网页一直部署不上去" class="headerlink" title="1. hexo d部署时一直出现“Connection reset”或“Connection redirected(?)”,之后弹出“Spawn failed”错误,导致生成的网页一直部署不上去"></a>1. hexo d部署时一直出现“Connection reset”或“Connection redirected(?)”,之后弹出“Spawn failed”错误,导致生成的网页一直部署不上去</h4><p><strong>问题描述</strong></p><p>在git bash界面中(当前路径在博客根目录),输入<code>hexo d</code>并运行,弹出类似于下面的错误信息:</p><center class="half"><img src="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/frequently_asked_questions_fig1_1.png" style="zoom: 60%;"></center><center><strong>图1.1</strong> 运行<code>hexo d</code>命令后,会弹出“Spawn failed”错误</center><p>尝试了网上的解决方案,没有效果,怀疑是网络连接问题。为验证部署错误是否由网络连接引起,在git bash界面中输入<code>ssh -T git@github.com</code>并运行,弹出下列错误提示:</p><center class="half"><img src="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/frequently_asked_questions_fig1_2.png" style="zoom: 60%;"></center><center><strong>图1.2</strong> 试图以SSH方式登录GitHub,会弹出“Connection reset”错误</center><p>考虑到图1.2是在实验室有线网下测试得到的,笔者又在校园网环境测试,结果如下:</p><center class="half"><img src="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/frequently_asked_questions_fig1_3.png" style="zoom: 60%;"></center><center><strong>图1.3</strong> 切换为校园网后,能以SSH方式成功登录GitHub</center><p>据此可以认为是本地Git服务与GitHub仓库之间的连接出现了问题。</p><p><strong>解决方案</strong></p><p>考虑到国内设立的“网络叹息之墙”,想要在国内直接连接GitHub可谓难于登天。目前尚能使用的解决方案如下:</p><p><strong>(1) 换用能连通GitHub的DNS</strong></p><p>目前(2022.11),国内无法访问GitHub的直接原因是DNS污染,因此,只要将GitHub及相关服务的域名,映射到尚未污染的IP地址,理论上就能访问GitHub。提供此类服务的网站很多,笔者较为推荐的是<a href="https://hosts.gitcdn.top/">Fetch GitHub Hosts</a>,它不但能提供实时更新的GitHub hosts文件,还附有集自动获取IP与配置hosts文件于一体的插件,能充分解决广大程序员无法访问GitHub的问题。</p><p><strong>(2) 开启移动热点或登录校园网</strong></p><p>CSDN部分博主发现,部分地区连接移动热点时,GitHub网站能正常访问,本地Git服务也能从GitHub仓库正常获取代码,这可能与部分地区移动服务尚未被污染有关。与此同理,教育网(大学校园网)因支持IPv6,且管理较为宽松,因此在教育网环境下,GitHub没有遭受DNS污染,可以正常访问与使用。</p><p><strong>(3) 使用GitHub Desktop</strong></p><p>如果更换DNS不起作用,又没有不被DNS污染的网络环境,但还能使用代理服务器的话,GitHub Desktop是一个不错的选择,它的使用方法,可以参考<a href="/2022/11/20/guide-to-creating-a-GitHub-page-with-Hexo-framework-sequel">基于Hexo框架的GitHub个人主页搭建教程(后篇)</a>的第六部分。</p><p><strong>(4) 手动配置本地Git的代理选项</strong></p><p>当然,倘若你真的不喜欢GitHub Desktop的图形化界面,又或者对命令行的Git bash有特殊需求,那么在能确保代理服务器能正常运行的前提下,最后的救命稻草,就是手动配置本地Git的代理选项。</p><p>首先,我们要明确的一点,就是Git插件可通过两种连接协议,访问远程的Git仓库(包括GitHub),一种协议是HTTP或HTTPS协议,例如根据GitHub仓库的网页链接,从GitHub下载源码:</p><pre><code class="lang-bash">git clone https://github.com/chemlzh/chemlzh.github.io</code></pre><p>另一种是SSH协议,例如利用GitHub的SSH服务,将本地代码上传至远程仓库:</p><pre><code class="lang-bash">git push git@github.com:chemlzh/chemlzh.github.io.git</code></pre><p>对于HTTP/HTTPS协议,如果要设置代理服务器,则在Git bash中输入如下命令:</p><pre><code class="lang-bash">git config --global http.proxy http://127.0.0.1:portgit config --global https.proxy http://127.0.0.1:port</code></pre><p>此处的<code>port</code>意为代理服务器使用的端口,该端口可通过“打开‘网络与Internet’设置”→“代理”→“手动设置代理”得知,见下图1.4。</p><center class="half"><img src="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/frequently_asked_questions_fig1_4.png" style="zoom: 40%;"></center><center><strong>图1.4</strong> “代理”设置能反映出代理服务器的端口</center><p>如果要取消代理设置,则在Git bash中输入如下命令:</p><pre><code class="lang-bash">git config --global --unset http.proxygit config --global --unset https.proxy</code></pre><p>对于SSH协议,如果要设置代理服务器,则打开<code>C:\Users\(your_username)\.ssh\config</code>(Windows用户)或<code>~/.ssh/config</code>(Linux或Mac用户),在其中添加如下内容并保存:</p><pre><code class="lang-bash"># For Linux or Mac OS XHost github.com User git ProxyCommand nc -X connect -x 127.0.0.1:7890 %h %p# For WindowsHost github.com User git ProxyCommand connect -H 127.0.0.1:7890 %h %p</code></pre><p>如果要取消代理设置,则将SSH的config文件中关于GitHub的部分删除或注释,之后保存即可。</p><p><strong>参考资料</strong></p><p><a href="https://blog.csdn.net/QianQiYing/article/details/104999948?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-3-104999948-blog-103767426.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-3-104999948-blog-103767426.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=4">reset by 192.30.255.112 port 22;connect to host github.com port 22: Connection timed out——解决问题的过程记录</a></p><p><a href="https://liyangweb.com/webnear/689.html">Github打不开怎么办</a></p><p><a href="https://blog.csdn.net/qq_37754830/article/details/122606405?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-9-122606405-blog-104999948.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-9-122606405-blog-104999948.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=9">ssh: connect to host github.com port 22 修改端口不起效情况下的解决方法</a></p><p><a href="https://itsmycode.com/configure-git-proxy/">How to configure Git proxy?</a></p><p><a href="https://ericclose.github.io/git-proxy-config.html">一文让你了解如何为 Git 设置代理</a></p><h3 id="Node-js与Hexo部分"><a href="#Node-js与Hexo部分" class="headerlink" title="Node.js与Hexo部分"></a>Node.js与Hexo部分</h3><h4 id="1-我按照网上的教程,把Node-js源换成阿里源了,可为什么还是没法顺利下载hexo包呢"><a href="#1-我按照网上的教程,把Node-js源换成阿里源了,可为什么还是没法顺利下载hexo包呢" class="headerlink" title="1. 我按照网上的教程,把Node.js源换成阿里源了,可为什么还是没法顺利下载hexo包呢"></a>1. 我按照网上的教程,把Node.js源换成阿里源了,可为什么还是没法顺利下载hexo包呢</h4><p>目前网上的换源教程,都会推荐使用国内的阿里源,这样可以避免由大防火墙带来的下载中断等问题。但要注意的是,自2022年5月底开始,原阿里npm源域名<a href="http://npm.taobao.org">http://npm.taobao.org</a>和<a href="registry.npm.taobao.org">registry.npm.taobao.org</a>停止使用,启用的新域名分别为<a href="http://npmmirror.com">http://npmmirror.com</a>和<a href="registry.npmmirror.com">registry.npmmirror.com</a>。而绝大部分教程(如<a href="https://www.jianshu.com/p/09e98b1072dc">这篇</a>)都是在2022年5月前发布的,且发布后没有及时更新,因此提供的阿里源网址仍是老网址,使用后有可能提示无法访问或下载npm包。</p><p><strong>解决方案</strong></p><p>在命令行终端输入下列命令并运行,将npm源替换为新的阿里源</p><pre><code class="lang-bash">npm config set registry https://registry.npmmirror.com</code></pre><p><strong>参考资料</strong></p><p><a href="https://www.jianshu.com/p/09e98b1072dc">npm install报错ERR! code ETIMEDOUT的解决办法</a></p><p><a href="https://zhuanlan.zhihu.com/p/465424728">【公告】淘宝 npm 域名即将切换 && npmmirror 重构升级 && 微信交流群</a></p><h4 id="2-看新的阿里源推荐使用cnpm,这个cnpm与原来的npm有什么关系?"><a href="#2-看新的阿里源推荐使用cnpm,这个cnpm与原来的npm有什么关系?" class="headerlink" title="2. 看新的阿里源推荐使用cnpm,这个cnpm与原来的npm有什么关系?"></a>2. 看新的阿里源推荐使用cnpm,这个cnpm与原来的npm有什么关系?</h4><p><strong>太长不看版</strong></p><p>(1) npm即Node.js包管理器(node package manager),用于Node.js插件管理(包括安装、卸载、管理依赖等),cnpm是npm下属的一个插件包;(2) 实际使用时,cnpm等同于npm,但由于使用了国内的镜像源,因此更新Node.js插件的速度远快于npm</p><p><strong>详细解答</strong></p><p>正如“太长不看版”所述,npm即Node.js包管理器,它负责每个Node.js插件的安装、卸载与版本依赖,以及不同版本插件的配置与管理。当npm工作时,它必须从<a href="https://registry.npmjs.org/">官方插件库</a>中获取待修改插件的信息与数据,然后才能进行下一步的修改。然而,由于“网络叹息之墙”的存在,国内与npm官方源的连接十分不稳定,容易出现连接超时甚至无法访问的现象。有鉴于此,npmmirror镜像(即原阿里源)团队开发了一个叫cnpm的Node.js插件,它继承了npm的所有功能,同时采用国内的镜像源下载插件,因此更新Node.js插件的速度远快于npm。</p><p>不过,考虑到cnpm默认使用的是软链接,因此npm安装了新插件后,极有可能更新了之前的cnpm包,然后之前cnpm的软链接就会……全 部 木 大!</p><p>所以,为了防止今后随时可能出现的包管理错误,还是老老实实用如下方式设置npmmirror镜像:</p><pre><code class="lang-bash">npm config set registry https://registry.npmmirror.com</code></pre><p><strong>参考资料</strong></p><p><a href="https://www.cnblogs.com/chase-star/p/10455703.html">npm 和 cnpm 的区别,你真的搞懂了嘛</a></p><p><a href="https://juejin.cn/post/6878194344273117192">npm和cnpm混用的坑</a></p><h4 id="3-为什么在安装完hexo-cli后,执行hexo-init仍然报错,说找不到“hexo”命令?"><a href="#3-为什么在安装完hexo-cli后,执行hexo-init仍然报错,说找不到“hexo”命令?" class="headerlink" title="3. 为什么在安装完hexo-cli后,执行hexo init仍然报错,说找不到“hexo”命令?"></a>3. 为什么在安装完hexo-cli后,执行hexo init仍然报错,说找不到“hexo”命令?</h4><p><strong>太长不看版</strong></p><p>有没有一种可能,是你设置了本地环境,却忘记添加对应的环境变量?</p><p><strong>详细解答</strong></p><p>有些人在安装完Node.js后,会按照<a href="https://blog.csdn.net/github_39655029/article/details/105397485">Windows 下 Node.js 的安装图文教程</a>,更改Node.js包的安装路径,却没有将安装路径一并添加到全局环境变量PATH中,导致安装hexo-cli后,系统无法得到hexo对应的“正确的”运行程序,因此认为找不到“hexo”命令</p><p><strong>解决方案</strong></p><p>以Windows为例,依次打开“设置”→“系统”→“关于”,点击右侧的“高级系统设置”,弹出“系统属性”窗口,然后直接点击“环境变量”:</p><center class="half"><img src="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/frequently_asked_questions_fig2_1.png" style="zoom: 40%;"></center><center><strong>图2.1</strong> 在Windows系统中打开环境变量设置</center><p>此时会打开Windows的环境变量窗口,我们到“全局变量”中找到<code>Path</code>,点击“编辑”,弹出“编辑环境变量”窗口,再点击“新建”。</p><center class="half"><img src="/2022/11/18/frequently-asked-questions-on-creating-a-GitHub-page/frequently_asked_questions_fig2_2.png" style="zoom: 40%;"></center><center><strong>图2.2</strong> 在环境变量设置窗口,编辑系统变量<code>Path</code></center><p>在新打开的框中,填入hexo-cli的安装路径,然后单击“确定”,譬如笔者的安装路径为</p><pre><code class="lang-markdown">C:\Program Files\nodejs\node_global\node_modules\hexo-cli\bin</code></pre><p><strong>参考资料</strong></p><p>(暂无)</p><h3 id="Material主题部分"><a href="#Material主题部分" class="headerlink" title="Material主题部分"></a>Material主题部分</h3><h4 id="1-hexo-g生成本地网页出错,错误信息中含有“Cannot-read-property-‘startsWith’-of-null”、“dnsprefetch”等字眼,hexo-clean以后错误仍然存在"><a href="#1-hexo-g生成本地网页出错,错误信息中含有“Cannot-read-property-‘startsWith’-of-null”、“dnsprefetch”等字眼,hexo-clean以后错误仍然存在" class="headerlink" title="1. hexo g生成本地网页出错,错误信息中含有“Cannot read property ‘startsWith’ of null”、“dnsprefetch”等字眼,hexo clean以后错误仍然存在"></a>1. hexo g生成本地网页出错,错误信息中含有“Cannot read property ‘startsWith’ of null”、“dnsprefetch”等字眼,hexo clean以后错误仍然存在</h4><p>根据<a href="https://easyhexo.com/">EasyHexo</a>的安装指南,如果下载安装的是hexo-theme-material 1.5.2,应该不会出现这一错误。因此可以肯定的是,该错误主要出现在hexo-theme-material 1.5.5及更新版本。</p><p>从hexo-theme-material的Issue #709可知,该错误来自于dnsprefetch.ejs的第21行:</p><pre><code class="lang-javascript"><% } else if(theme.comment.use.startsWith("disqus")) { %></code></pre><p>这一部分原本作用是调用disqus评论服务,但在版本更迭的过程中,作者似乎忘记了theme.comment.use可能没有初始化(或等于null),因此没有加一条“是否开启(特定的)博客评论服务”的判断语句,导致布尔判断语句出错,进而导致后续的网页生成错误。</p><p><strong>解决方案</strong></p><p>a) 如果对Material主题包的版本不介意的话,安装旧版本的Material主题包即可解决问题。旧版本的Material主题包在<a href="https://github.com/iblh/hexo-theme-material/releases">Material Releases</a>中,下拉找到1.5.2版,下载后按照教程安装即可。</p><p>b) 如果执意采用高于1.5.2的Material主题包,解决方案则是直接修改dnsprefetch.ejs的出错语句。假设Material主题包放在了博客的themes文件夹下,名字叫hexo-theme-material,则dnsprefetch.ejs应该位于<code>/(your_blog_name)/themes/hexo-theme-material/layout/_widget</code>。找到dnsprefetch.ejs,用记事本(或VSCode)打开,定位到第21行(查找“startsWith”也能定位到该语句),将其改为:</p><pre><code class="lang-javascript"><% } else if(theme.comment.use && theme.comment.use.startsWith("disqus")) { %></code></pre><p>保存后在博客根目录下启动git bash,输入hexo clean后运行,再输入hexo g重新生成,这样便能解决上述错误。</p><p><strong>参考资料</strong></p><p><a href="https://github.com/iblh/hexo-theme-material/issues/709">hexo g出错 hexo clean以后无效 按照hexo文档进行的操作 (Issue #709)</a></p><h4 id="2-安装hexo-render-mathjax后,有时在语句两端各加两个星号,非但不能加粗字体,反而出现了部分字符重复出现的错误,怎么解决?"><a href="#2-安装hexo-render-mathjax后,有时在语句两端各加两个星号,非但不能加粗字体,反而出现了部分字符重复出现的错误,怎么解决?" class="headerlink" title="2. 安装hexo-render-mathjax后,有时在语句两端各加两个星号,非但不能加粗字体,反而出现了部分字符重复出现的错误,怎么解决?"></a>2. 安装hexo-render-mathjax后,有时在语句两端各加两个星号,非但不能加粗字体,反而出现了部分字符重复出现的错误,怎么解决?</h4><p><strong>解决方案</strong></p><p>这应该是hexo-render-mathjax对部分转义字符,尤其是<code>/</code>字符的解析出现偏差导致的,因此,将前后的两个星号,替换为<code><strong></strong></code>,基本上就能解决大部分字符莫名其妙重复的问题。同理,如果原来是程序语句的部分,也出现了字符重复的渲染错误,则将原来的<code>``</code>改写为<code><code></code></code>。</p><p>(这不就是告诫我们,多学一点HTML嘛!嗐!)</p><p><strong>参考资料</strong></p><p>(暂无)</p>]]></content>
<categories>
<category> 网络技术 </category>
</categories>
<tags>
<tag> GitHub </tag>
<tag> Hexo </tag>
<tag> Node.js </tag>
<tag> Material主题 </tag>
</tags>
</entry>
<entry>
<title>基于Hexo框架的GitHub个人主页搭建教程(前篇)</title>
<link href="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/"/>
<url>/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/</url>
<content type="html"><![CDATA[<p>一年前的暑假,笔者曾经对照着网上的教程,试着弄一个专属于自己的GitHub主页,但由于笔者对具体的技术细节不太熟悉,加之时间不太充裕,写作灵感又极其匮乏,于是套了个Material主题后就不了了之。</p><p>最近适逢疫情严峻,笔者无法顺利开展实验,于是决定重拾计算机的“老本行”,钻研一下如何搭建自己的GitHub主页。经过这一两天的努力,笔者终于完成了GitHub个人主页的搭建,接下来只需要对博客进行小修小补,并搞清楚版本管理与部署即可。</p><p>也许有人会问,按你的说法,用Hexo搭建GitHub个人主页,只需要一天搭框架,一天修故障,不是易如反掌的事?但换个角度想,笔者毕竟没有按部就班照着一份系统的教程来建主页,而是把网上的资料东拼西凑,才勉强搭了一个能用的,其中踩过的坑和绕过的远路,只有自己知晓。为了避免今后再费周折,笔者决定写下这篇教程,既是给自己准备一份建站的参考资料,也可以用来帮助其他初涉Hexo,希望用它搭建博客的爱好者。</p><p>既然这样,那……就开始了?</p><h3 id="Part-0-Git是啥?GitHub又是啥?为啥要用GitHub做个人主页?"><a href="#Part-0-Git是啥?GitHub又是啥?为啥要用GitHub做个人主页?" class="headerlink" title="Part 0. Git是啥?GitHub又是啥?为啥要用GitHub做个人主页?"></a>Part 0. Git是啥?GitHub又是啥?为啥要用GitHub做个人主页?</h3><p>Git是一款基于快照(snapshot-based)的分布式版本控制(distributed version control)工具。“基于快照”意味着,当一个用户用Git更新文件(如一段代码)时,Git不会为每个文件保存一个版本,而是先计算文件的哈希码,并与之前的版本比较,如果哈希码相同,Git便会记下一个链接,这个链接指向上一个版本储存的文件,如果哈希码不同,Git则会创建一个快照,并保存这个快照的索引,如图0.1所示。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig0_1.png" style="zoom: 60%;"></center><center><strong>图0.1</strong> Git的“基于快照”的版本控制思路</center><p>而“分布式”意味着,任何一个开发者,都可以在自己的电脑上,存储自己编辑的当前版本的文件,以及这些文件从创建,到每一次修改,最后变成现在的本地存储版本的过程。这样,即使开发者与(存储主干版本的)公共服务器断开连接,开发者仍然能用自己的电脑,对文件进行增删与修改,并且在本地提交版本更新,等到与公共服务器重连后,再提交pull request,然后与主干版本合并,从而大大提高了开发效率(见图0.2)。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig0_2.png" style="zoom: 60%;"></center><center><strong>图0.2</strong> Git的“分布式”存储思路</center><p>虽然Git是分布式版本控制工具,但正如前面提到的那样,为了保证有一个稳定的主干版本,供不同的开发者下载与修改,必须要设立一台公共服务器,用以存储主干版本的文件。这台公共服务器,既可以由开发者亲自组装搭建,也可以来自于具有代码托管能力的商业公司(即Git server as a service),而GitHub便是其中历史悠久(2008年创立),规模最大(超过8千万的用户,超过2亿的代码仓库,其中开放仓库近3千万),也是最富盛名的Git服务平台,其简洁易用的界面、丰富的代码资源、友好的社区氛围,为搭建个人网站提供了极大的便利。</p><p>也许稍微懂行一点的朋友会问:为什么你这么推荐GitHub,而不推荐GitLab或Gitee呢?毕竟,如果不更换DNS,也不用校园网,GitHub很容易因为网络问题,无法拉取或上传代码,导致个人网页难以持续更新,而用GitLab或Gitee,则大概率可以避免这些问题。不错,GitHub确实有网络不畅的痛点(这个在之后的<a href="/2022/11/18/frequently-asked-question-on-creating-a-GitHub-page">疑难解答</a>中也会提及),然而把GitLab或Gitee当GitHub的代餐,遇到棘手问题的概率更大,找不到解决方案的概率也更大,因为互联网环境下,讨论GitHub使用方法的帖子和文章,远比讨论GitLab或Gitee的要多。</p><p>此外,像Gitee之类的国内Git服务平台,还存在两个头疼的问题:其一,这些平台更多面向国内用户,国际市场开拓不大,若决定常驻这些平台,便会错过许多来自国外开发者的优质代码,以及与这些国外开发者沟通交流,切磋技艺的机会;其二,向Gitee等国内平台提交代码后,由于平台的自我审核机制,这些代码基本上不能第一时间上传并展示在平台网站上,这就导致若是提交软件源码,其他用户并不能立即享受新版本软件的便利,若是提交个人博客的文章,其他用户也不能第一时间关注。鉴于这两点,笔者建议,<strong>如果GitHub能正常登陆,且能正常拉取/提交代码,仍应将GitHub作为代码仓库与个人网页的首选。</strong></p><h3 id="Part-I-前期准备:GitHub账号的申请,GitHub主页仓库的创建,以及本地Git环境的配置"><a href="#Part-I-前期准备:GitHub账号的申请,GitHub主页仓库的创建,以及本地Git环境的配置" class="headerlink" title="Part I. 前期准备:GitHub账号的申请,GitHub主页仓库的创建,以及本地Git环境的配置"></a>Part I. 前期准备:GitHub账号的申请,GitHub主页仓库的创建,以及本地Git环境的配置</h3><h4 id="注册个人GitHub账号,在其中创建GitHub主页对应的代码仓库"><a href="#注册个人GitHub账号,在其中创建GitHub主页对应的代码仓库" class="headerlink" title="注册个人GitHub账号,在其中创建GitHub主页对应的代码仓库"></a>注册个人GitHub账号,在其中创建GitHub主页对应的代码仓库</h4><p>为了建立GitHub主页,首先我们要创建一个GitHub账号,并在这个账号中创建一个代码仓库,用于存储发布在GitHub主页的文章,以及运行GitHub主页所需要的代码。为此,我们在浏览器中访问<a href="GitHub.com">GitHub.com</a>,这将弹出图1.1所示的界面,点击右上角的“Sign up”按钮,GitHub将会自动跳转到注册页面。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_1.png" style="zoom: 40%;"></center><center><strong>图1.1</strong> GitHub首页界面,注册按钮用红框标出</center><p>注册页面会提示输入邮箱,一般用自己经常使用的邮箱(学校邮箱、网易邮箱、QQ邮箱皆可)。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_2.png" style="zoom: 40%;"></center><center><strong>图1.2</strong> GitHub注册界面,提示你输入邮箱</center><p>之后依次输入用户名和账号密码,点击确认,GitHub会发送认证邮件,我们只需打开邮箱,进入认证邮件,点击认证链接,即可完成注册。</p><p>注册后,我们登录GitHub账号,进入用户界面,点击右上角的加号(在你的缩略头像左侧),会弹出一个下拉菜单,点击“New repository”,就会转到代码仓库的创建页面,如图1.3所示。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_3.png" style="zoom: 40%;"></center><center><strong>图1.3</strong> 从GitHub用户界面创建代码仓库(<del>对不起我是二次元</del>)</center><p>我们给即将创建的代码仓库,命名为<code>(your_username).github.io</code>,此处的<code>(your_username)</code>应与当前登录的GitHub账号名称(不是昵称!)相同,此外,还要保证这个代码仓库勾选的是“Public”而非“Private”,这样其他人才能访问你的界面。确保选项无误后,点击下方的绿色按钮“Create repository”,GitHub就会生成GitHub主页对应的代码仓库。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_4.png" style="zoom: 75%;"></center><center><strong>图1.4</strong> 把即将创建的代码仓库命名为<code>(your_username).github.io</code>,注意到命名区为红色,表明同名仓库已被创建</center><h4 id="在本地环境安装Git,并以SSH方式关联本地Git与GitHub"><a href="#在本地环境安装Git,并以SSH方式关联本地Git与GitHub" class="headerlink" title="在本地环境安装Git,并以SSH方式关联本地Git与GitHub"></a>在本地环境安装Git,并以SSH方式关联本地Git与GitHub</h4><p>根据Part 0的描述可知,仅仅在GitHub申请账号和建立代码仓库,而没有建立本地的Git环境,或是建立了Git环境,却没有将其与GitHub关联,仍然不能把博客页面上传到GitHub部署。因此,我们要做的下一步工作,就是在本地计算机上安装Git,然后在Git bash中登陆自己的GitHub账号,最后配置SSH公钥,便于之后拉取或上传代码时,以SSH方式关联本地Git与GitHub。</p><p>Git的官方网站是<a href="https://git-scm.com/">https://git-scm.com/</a>,进入页面后会有一个大大的“Downloads”,点进去就会跳转到下载界面。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_5.png" style="zoom: 40%;"></center><center><strong>图1.5</strong> Git的官方网站,已标出下载入口</center><p>考虑到我们是在Windows下更新GitHub个人主页,这里我们直接点“Windows”,下载适用于Windows系统的Git套件。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_6.png" style="zoom: 40%;"></center><center><strong>图1.6</strong> Git的下载界面,Windows用户点选“Windows”即可</center><p>下载完毕后,双击安装包运行,勾选“同意使用协议”,之后选项全部默认,一路点击Next,等待安装程序执行完毕后,点击“Finish”完成安装。</p><p>通常情况下,Git套件安装后便能立即使用,如果不放心,可以在命令行中输入<code>git --version</code>并执行,若弹出<code>git version ×.×.×.windows.×</code>,且与安装包对应版本一致,便说明Git组件安装成功。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_7.png" style="zoom: 120%;"></center><center><strong>图1.7</strong> 验证Git是否安装成功</center><p>有了Git组件,我们就可以用Git上传我们的博客文章,或是下载博客所需的主题文件,是不是离搭建GitHub个人主页又近了一步?不过别高兴太早,在正式搭建个人主页前,我们还要做一件非常重要的事,那就是在Git bash上登录自己的GitHub账号,并且为之后的登录配置SSH密钥。</p><p>那这里可能有人要问了,我每次拉取或提交代码,就想跟GitHub对着干,我偏偏不用SSH登录,就手动输入密码,可不可以?曾经很长一段时间,笔者就是这么做的,GitHub也默许通过密码登录,在本地Git与GitHub之间建立连接的行为。然而,2021年8月,GitHub宣布,<a href="https://github.blog/changelog/2021-08-12-git-password-authentication-is-shutting-down/">不再支持通过GitHub账户密码验证本地Git操作</a>,这意味着任用户一千个不同意,也得使用SSH方式登录,这或许就是大公司的威严吧……</p><p>无论如何,我们还是要打开Git bash,输入如下命令,登录你的GitHub账号,也让本地Git记住自己的GitHub用户名(对应于命令中的[your_username])和注册邮箱(对应于命令中的[your_email]):</p><pre><code class="lang-bash">git config --global user.name [your_username]git config --global user.email [your_email]</code></pre><p>要注意的是,第一次登录时,Git会提示你输入密码,但出于保密因素,除“Enter your password: ”这行系统提示消息外,<strong>命令行不会显示任何字符</strong>,也不会在你输入或删除字符时用增减星号(井号)表示,<strong>因此输入密码时,最好放慢速度</strong>,避免因打字过快而输错。</p><p>下一步是生成适用于本地计算机的SSH密钥,为此要输入以下命令并运行,其中[your_email]仍然代表你注册GitHub时使用的邮箱:</p><pre><code class="lang-bash">ssh-keygen -t rsa -C user.email [your_email]</code></pre><p>此时会依次弹出如下提示,我们只需依次摁回车即可,不需要额外操作:</p><pre><code class="lang-bash">Enter file in which to save the key (/c/Users/tanglab_lzh/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:</code></pre><p>整个密钥生成过程如下图所示:</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_8.png" style="zoom: 75%;"></center><center><strong>图1.8</strong> 在Git bash登录GitHub账号与生成SSH密钥</center><p>ssh-keygen会将生成的私钥文件<code>id_rsa</code>与公钥文件<code>id_rsa.pub</code>放在以下目录(如果没有该文件夹,ssh-keygen会自行生成一个),故只要找到用户文件夹,将其下的.ssh文件夹打开,便能找到<code>id_rsa.pub</code>:</p><pre><code class="lang-bash">C:\Users\(computer_username)\.ssh</code></pre><p>用记事本打开<code>id_rsa.pub</code>,按Ctrl+A全选,再按Ctrl+C复制,然后按图1.9所示步骤,找到“SSH and GPG keys”选项卡,单击“New SSH key”,进入添加SSH密钥界面。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_9.png" style="zoom: 60%;"></center><center><strong>图1.9</strong> 找到“SSH and GPG keys”选项卡,进入添加SSH密钥界面</center><p>添加SSH密钥界面如图1.10所示,总计有三个框:“Title”代表密钥名称,一般用好记的名称表示;“Key type”代表密钥类型,有“验证密钥(Authentication key)”与“签名密钥(Signing key)”两种选项,此处保持“验证密钥”不动即可;“Key”为密钥内容,这是添加密钥的重点,我们把刚才从<code>id_rsa.pub</code>复制过来的内容粘贴到这个框,然后点选“Add SSH key”,生成的公钥就会添加到GitHub中。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_10.png" style="zoom: 60%;"></center><center><strong>图1.10</strong> 添加SSH密钥界面,其中的“Key”文本框要贴上<code>id_rsa.pub</code>的全部内容</center><p>最后,在命令行中输入如下命令,以SSH方式登录GitHub服务器:</p><pre><code class="lang-bash">ssh -T git@github.com</code></pre><p>如果命令行跳出<code>Hi [your_username]! You've successfully authenticated, but GitHub does not provide shell access.</code>,说明SSH密钥配置正确,你可以利用本地Git套件拉取或上传代码到GitHub。而如果命令行频繁跳出<code>Connection reset by [GitHub_SSH_IP] port 22</code>,则有可能是国内不可言说的网络环境所致,多尝试几次,或改用移动热点连接,或将端口切换至443,有可能改善此类情形。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig1_11.png" style="zoom: 75%;"></center><center><strong>图1.11</strong> 验证本地计算机能否通过SSH访问GitHub,注意到GitHub的22端口多次拒绝访问,可能与网络环境有关,为此笔者将登录端口切换至443</center><h3 id="Part-II-Node-js环境的安装,以及Hexo框架的初步搭建"><a href="#Part-II-Node-js环境的安装,以及Hexo框架的初步搭建" class="headerlink" title="Part II. Node.js环境的安装,以及Hexo框架的初步搭建"></a>Part II. Node.js环境的安装,以及Hexo框架的初步搭建</h3><h4 id="在Windows系统安装Node-js,并设置国内更新源"><a href="#在Windows系统安装Node-js,并设置国内更新源" class="headerlink" title="在Windows系统安装Node.js,并设置国内更新源"></a>在Windows系统安装Node.js,并设置国内更新源</h4><p>建立好GitHub主页仓库,并在本地配置好Git环境后,我们就可以依次安装Node.js和Hexo框架了。考虑到笔者主要在Windows上撰写博客文章,故以Windows环境为例,介绍Node.js和Hexo的安装流程,其他系统(如Mac OS X和Linux)的安装流程,可以参考<a href="https://hexo.io/zh-cn/docs/">Hexo中文文档</a>,这里暂不展开论述。</p><p>访问<a href="https://nodejs.org/en/download/">Node.js官方网站</a>(如果无法访问,可以访问<a href="https://npmmirror.com/mirrors/node/">npmmirror中国镜像站的Node.js镜像</a>),在“Windows Installer”一行,根据系统的位数点选(一般选64位下载,如图2.1所示),浏览器就会将对应位数的Node.js安装包下载到本地。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig2_1.png" style="zoom: 60%;"></center><center><strong>图2.1</strong> Node.js官方网站的下载页面,Windows用户通常点选64位安装包即可</center><p>双击安装包运行,勾选“同意使用协议”,之后选项全部默认,一路点击Next,等待安装程序执行完毕后,点击“Finish”完成安装。</p><p>为确保Node.js的所有组件均已正常安装,我们要打开命令提示符(Windows Powershell或Windows Terminal亦可),分别输入如下命令并运行:</p><pre><code class="lang-bash">node -vnpm -v</code></pre><p>如果分别跳出安装包对应的版本号(如图2.2所示),说明Node.js成功安装,否则应卸载Node.js,重新运行安装包进行安装。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig2_2.png" style="zoom: 120%;"></center><center><strong>图2.2</strong> 成功安装Node.js后,查询node和npm的版本号,会得到与安装包一致的结果</center><p>考虑到国内与Node.js软件包服务器的连接极不稳定,笔者推荐将npm源替换为npmmirror镜像源(即原阿里源,个中关系参见<a href="/2022/11/18/frequently-asked-question-on-creating-a-GitHub-page">疑难解答</a>的“Node.js与Hexo部分”),这一步骤非常简单,只需在命令行输入下列命令,回车执行即可:</p><pre><code class="lang-bash">npm config set registry https://registry.npmmirror.com</code></pre><p>当然,npmmirror还提供了另一种换源方法,就是用npmmirror定制的包管理工具cnpm代替npm,具体命令为:</p><pre><code class="lang-bash">npm install -g cnpm --registry=https://registry.npmmirror.com</code></pre><p>不过,笔者对cnpm并不熟悉,导致在后续的hexo安装时频频报错,最后决定放弃使用cnpm,改回原生的包管理工具npm。此外,也有知乎网友指出,换用cnpm后,因为cnpm奇葩的存放位置(hexo的软连接没有放在<code>/usr/local/bin</code>,而是放在<code>/var/root/.npm-global/lib/node_modules/hexo-cli/bin</code>),导致<a href="https://www.zhihu.com/question/332969173">即使正确安装hexo-cli,也找不到hexo命令</a>。<strong>综合以上两点,笔者建议直接用npm config更换npm源,而非采用cnpm来换源(毕竟安装cnpm时也要修改registry)</strong>。</p><h4 id="在本地部署Hexo框架,生成初始GitHub主页"><a href="#在本地部署Hexo框架,生成初始GitHub主页" class="headerlink" title="在本地部署Hexo框架,生成初始GitHub主页"></a>在本地部署Hexo框架,生成初始GitHub主页</h4><p>接下来,在你的工作区中,创建一个新文件夹,用以存放发布在GitHub主页的文章,以及运行GitHub主页所需要的代码(比如笔者就将其放在<code>C:\Workbench\chemlzh.github.io</code>)。然后,运行命令行(如果文件夹在C盘上,一定要以管理员权限运行命令行!否则没有读写权限!),并跳转到刚创建的文件夹。之后,输入下列命令,安装hexo的客户端版本:</p><pre><code class="lang-bash">npm i hexo-cli -g</code></pre><p>正常安装后,命令行通常会输出如下提示</p><blockquote><p>hexo-cli@(<i>version-number</i>)<br>added ×× packages from ×× contributors in ××s</p></blockquote><p>或是如下提示</p><blockquote><p>All packages installed (×× packages installed from npm registry, used ××s(network ××s), speed ××MB/s, json ××(××kB), tarball ××MB)</p></blockquote><p>如果没有看到类似于上述的提示,而是弹出红色或棕黄色的提示,并含有“error”、“unsuccessful”等字样,则表明hexo-cli没有安装成功(此时要么没有换成国内源,要么在安装过程中出现了强制中断、环境漏配等问题)。</p><p>确保hexo-cli安装成功后,依次输入以下命令并运行,让npm在新文件夹中初始化hexo环境,同时安装运行的必要组件:</p><pre><code class="lang-bash">hexo init .npm install</code></pre><p>如果hexo的环境变量配置正确,运行上述命令后,新文件夹中会成功生成如下文件:</p><pre><code class="lang-bash">../_config.yml # 网站配置信息./package.json # 在后续修改中安装的npm包的信息./package-lock.json # 初始化hexo环境时安装的npm包的信息./scaffolds # 模板文件夹./source # 用户文件夹,存放博客文章、图片等./source/_draft # 存放尚未发布的草稿./source/_posts # 存放正式发布的文章./themes # 主题文件夹</code></pre><p>最后,输入如下命令并依次运行,随后在浏览器中打开<a href="http://localhost:4000">http://localhost:4000</a>,便能在本地看到自己的博客界面。</p><pre><code class="lang-bash">hexo ghexo s</code></pre><p>不过,由于是首次创建,且尚未添加任何主题模板,因此显示的是hexo默认风格界面,且归档文章中只有一篇“hello world”。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig2_3.webp" style="zoom: 90%;"></center><center><strong>图2.3</strong> 首次创建hexo环境时,在本地显示的博客界面(图片引自<a href="https://zhuanlan.zhihu.com/p/111614119">随风的文章</a>)</center><p><strong>备注:</strong>如果按<a href="https://blog.csdn.net/github_39655029/article/details/105397485">Windows 下 Node.js 的安装图文教程</a>,修改了包存放路径,那么在运行<code>hexo init .</code>时,将会提示“hexo”命令不存在。此时,应依次打开“Windows设置”→“系统”→“关于”→“高级系统设置”→“环境变量”,将hexo-cli目录下的bin添加至PATH中(以笔者为例,便是在全局变量的PATH中,添加一条<code>C:\Program Files\nodejs\node_global\node_modules\hexo-cli\bin</code>),然后点击“确定”。随后,重新打开终端(若提示无读写权限,需以管理员身份打开),进入博客文件夹,重新运行<code>hexo init .</code>,此时该文件夹将正常生成hexo框架文件。在大部分情况下,该策略对未修改npm包存放路径,但提示“hexo”命令不存在的情形也有效(尚未测试)。</p><h3 id="Part-III-将Material主题应用到GitHub个人主页"><a href="#Part-III-将Material主题应用到GitHub个人主页" class="headerlink" title="Part III. 将Material主题应用到GitHub个人主页"></a>Part III. 将Material主题应用到GitHub个人主页</h3><h4 id="为什么不采用Hexo的默认主题,而采用自定义主题?"><a href="#为什么不采用Hexo的默认主题,而采用自定义主题?" class="headerlink" title="为什么不采用Hexo的默认主题,而采用自定义主题?"></a>为什么不采用Hexo的默认主题,而采用自定义主题?</h4><p>请诸位回到Part II的结尾部分,看一看Hexo的默认风格界面吧。诚然,这个界面以白色与灰色为主色调,没有东拼西贴的小广告,与10-20年前绝大多数网站相比,可谓是简洁清爽。但仔细一想,总感觉缺了点什么——或许,对某些人而言,默认界面缺的是鲜明的色彩,扁平化的界面设计;或许,对某些人而言,默认界面缺的则是黑白的对比,棱角分明的冷艳感。</p><p>除渲染风格较为乏味外,Hexo的默认风格界面,还缺了许多有意思的功能选项:例如,我想给每篇文章加一张亮眼的题图,可是默认界面的文章根本不会显示题图;我想把归档日志和最近发表折叠到边栏,可是默认界面显示的是顶栏,而且主界面中并没有把归档日志收纳起来……</p><p>显然,建站者日益增长的审美与实用需求,与默认主题较为贫瘠的生产力之间,产生了巨大的矛盾,这促使广大的开发者对Hexo主题进行个性化修改,自定义主题因此诞生。</p><p>想要色彩鲜明的扁平化设计?Material主题就很适合你:</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_1.png" style="zoom: 40%;"></center><center><strong>图3.1</strong> Material主题演示页(<a href="https://iblh.github.io/material-demo/">原网页见此</a>)</center><p>想要遵循KISS原则的教诲,在黑白二色间自由翱翔?那就尝试一下NexT主题:</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_2.png" style="zoom: 40%;"></center><center><strong>图3.2</strong> NexT主题演示页(<a href="https://theme-next.org/">原网页见此</a>)</center><p>甚至,看官想来点二次元?也有大手子做好了明日方舟主题:</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_3.png" style="zoom: 40%;"></center><center><strong>图3.3</strong> Arknight主题演示页(<a href="https://ark.theme.yueplus.ink/">原网页见此</a>)</center><p>可以说,除了极其个性化的设计外(这得自己动手丰衣足食),任何你想到的界面风格,都可以在GitHub上找到对应的主题源码,只要正确的下载与安装,再加上适当的调参,便能将单调的Hexo初始页面,打造为炫酷的个人主页!</p><p>好了,废话少说,让我们看看怎么在初始的Hexo框架上,添加Material主题吧。至于为什么要采用Material主题,笔者在这一节的结尾给出了充分的理由,请诸位务必往下阅读哦!</p><h4 id="如何添加Material主题"><a href="#如何添加Material主题" class="headerlink" title="如何添加Material主题"></a>如何添加Material主题</h4><p>Material主题目前由iblh等人开发与维护,其所有发布版本均可从<a href="https://github.com/iblh/hexo-theme-material/releases">GitHub Releases</a>中获取,这里我们由两种选择:一是下载发布较早,但Bug较少的1.5.2版本,二是下载最新发布,但存在较多Bug的1.5.6版本。如果是Hexo新手,建议下载1.5.2版本,以避免之后生成页面失败的问题;如果对自己的编程纠错能力有一定把握,可以选择1.5.6尝鲜。进入<a href="https://github.com/iblh/hexo-theme-material/releases">GitHub Releases</a>,点击“Source code (zip)”,就会自动下载对应版本的Material主题包,如图3.4所示</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_4.png" style="zoom: 40%;"></center><center><strong>图3.4</strong> 在Releases页面下载1.5.6版Material主题包(旧版本下拉即可找到)</center><p>将下载的1.5.6版Material主题包解压缩,得到一个叫“hexo-theme-material-1.5.6”的文件夹,考虑到我们不需要标注版本号,故更名为“hexo-theme-material”。然后,打开本地个人主页的根目录,找到“themes”文件夹并进入,再将“hexo-theme-material”复制到“themes”文件夹下。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_5.png" style="zoom: 75%;"></center><center><strong>图3.5</strong> 进入博客根目录的“themes”文件夹,将更名后的Material主题文件夹复制到“themes”下</center><p>刚刚解压的Material主题包,还没有添加任何格式设置,因此我们要打开<code>themes/hexo-theme-material</code>,找到_config.template.yml,并在原地拷贝一份,旧有的_config.template.yml保持原样(或改名为_config.template_duplicated.yml,以防与根目录下的_config.template.yml冲突),新拷贝的改名为_config.yml,它代表针对Material主题的设置(而非Hexo框架的设置)。</p><p>之后,我们回到个人主页的根目录,打开其下的_config.yml(代表Hexo框架的设置,注意不要与主题文件夹下的_config.yml混淆),修改图3.6红框所示的内容。其中,title代表个人主页的标题;author代表博客文章的默认作者;language代表网页界面默认使用的语言文字,中文用户一般填“zh-CN”即可;url为博客网址,对于GitHub个人主页而言,如果不额外绑定域名,一般为<code>https://(your_username).github.io/</code>。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_6.png" style="zoom: 90%;"></center><center><strong>图3.6</strong> 编辑个人主页根目录_config.yml的部分参数</center><p>最后,我们下拉到<code>theme:</code>选项,填入放在themes文件夹下的Material主题包的名字(此处为“hexo-theme-material”),如图3.7所示,便可以保存_config.yml并退出了。</p><center class="half"><img src="/2022/11/18/guide-to-creating-a-GitHub-page-with-Hexo-framework/creating_GitHub_pages_fig3_7.png" style="zoom: 90%;"></center><center><strong>图3.6</strong> 在根目录_config.yml中启用Material主题</center><p>回到个人主页的根目录,点下右键,选择菜单中的“Git bash here”,启动Git bash,依次输入以下命令并运行。</p><pre><code class="lang-bash">hexo clean # 清除public文件夹下的所有文件hexo g # 将网页生成在public文件夹下hexo s # 启动本地服务器预览</code></pre><p>如果使用的是1.5.2版,网页源代码将会正常生成,此时,在浏览器中打开<a href="http://localhost:4000">http://localhost:4000</a>,应该就能得到与图3.1相似的网页界面了。(如果是1.5.6版,可以参考<a href="/2022/11/18/frequently-asked-question-on-creating-a-GitHub-page">疑难解答</a>的“Material主题部分”,修改<code>/(your_blog_name)/themes/hexo-theme-material/layout/_widget</code>下的dnsprefetch.ejs,然后重新生成网页)</p><p><strong>注意:</strong>修改_config.yml时,一定要注意书写格式!首先,选项名称后的冒号一定得是英文的冒号<code>:</code>,而不是中文的冒号<code>:</code>。其次,选项名称与冒号之间没有空格,而冒号与后面的选项取值之间,则有一个半角空格。<strong>任何没有按照上述标准添加或修改的选项,其导致的无法生成网页的html代码等后果,均由修改者承担!</strong></p><h4 id="私货:为什么选择了Material主题?"><a href="#私货:为什么选择了Material主题?" class="headerlink" title="私货:为什么选择了Material主题?"></a>私货:为什么选择了Material主题?</h4><p><strong>太长不看版:</strong>因为NexT主题太过朴素,适合于程序员总结经验,却不适合于向他人展示成果;而Material主题色彩鲜明,界面扁平化,还能给每篇文章添加自选题图。</p><p><strong>详细解释:</strong>如果你搜索“常用/好看的Hexo主题”,十有八九会有人力荐NexT主题,因为它界面简洁,只有黑白两种配色,没有多余的按钮,也没有冗杂的颜色,非常适合程序员阅读。而从GitHub的Star数看,最受欢迎的Hexo主题,NexT当之无愧(新版本7.8K,作为对比,Material主题的Star数为4K)。不过,从调动阅读兴趣的角度看,黑白配色也是一把“双刃剑”——任何枯燥的技术性内容,搭配上一眼望不到头的白底黑字或黑底白字,都将是效果拔群的“催眠模因”,刚开始可能还不太在意,读了5-10分钟才发现:这篇文章怎么还没结束!太无聊了,不看不看!</p><p>相反,Material主题运用了多种饱和度较高的颜色,且色彩搭配非常和谐,这在一定程度上减轻了阅读的困倦感;扁平化的设计风格,则将杂乱无章的超链接,统一为方正而易于识别的按钮,有一种规整、轻盈的“赛博美感”。此外,Material还为每一篇文章,添加了随机选取的题图。倘若博主觉得不太满意,还能结合第三方插件,将题图更换为萌萌哒的二次元同人图,既提升了阅读效率,又能温暖一下阿宅孤单的心灵呢(笑)。</p><p>(当然,也有人认为,色彩过于鲜艳,或是添加的二次元同人图太多,时间长了反倒会有生理与精神上的双重疲劳,因此不喜欢花花绿绿的风格。这个问题仁者见仁智者见智,至少对于我而言,NexT风格的网页不太能调得动我的兴趣)</p><h3 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h3><p><strong>Part 0:</strong></p><p><a href="https://blog.csdn.net/wanglin_lin/article/details/48845343">版本控制工具(CVS、SVN、GIT)简介</a></p><p><strong>Part I:</strong></p><p><a href="https://www.runoob.com/git/git-remote-repo.html">Git 远程仓库(Github)</a></p><p><a href="https://www.runoob.com/w3cnote/git-guide.html">Github 简明教程</a></p><p><a href="https://github.blog/changelog/2021-08-12-git-password-authentication-is-shutting-down/">Git password authentication is shutting down</a></p><p><strong>Part II:</strong></p><p><a href="https://hexo.io/zh-cn/docs/">Hexo中文文档</a></p><p><a href="https://blog.csdn.net/github_39655029/article/details/105397485">Windows 下 Node.js 的安装图文教程</a></p><p><a href="https://www.zhihu.com/question/332969173">安装hexo 提示 command not found,怎么解决?</a></p><p><strong>Part III:</strong></p><p><a href="https://neko-dev.github.io/material-theme-docs/#/">Material Theme Docs</a></p><p><a href="https://easyhexo.com/2-Theme-use-and-config/2-5-hexo-theme-material/">hexo-theme-material | Easy Hexo</a></p><p><a href="https://www.zhihu.com/question/24422335">有哪些好看的 Hexo 主题?</a></p><p><a href="https://blog.csdn.net/zgd826237710/article/details/99671027">Hexo 好看的主题推荐</a></p>]]></content>
<categories>
<category> 网络技术 </category>
</categories>
<tags>
<tag> GitHub </tag>
<tag> Hexo </tag>
<tag> Node.js </tag>
<tag> Material主题 </tag>
</tags>
</entry>
<entry>
<title>量子力学视角下的核磁共振波谱(Part 1:量子力学预备知识)</title>
<link href="/2022/11/17/NMR-spectroscopy-under-the-perspective-of-quantum-mechanics-I/"/>
<url>/2022/11/17/NMR-spectroscopy-under-the-perspective-of-quantum-mechanics-I/</url>
<content type="html"><![CDATA[<h3 id="0-前言"><a href="#0-前言" class="headerlink" title="0. 前言"></a>0. 前言</h3><p>本系列文章根据笔者对量子力学和核磁共振的学习经验与感悟总结而得,可以视为对核磁共振物理图景较为粗略浅显的描述。按照笔者的规划,预计至少应有三个部分。</p><p>在第一部分,笔者主要对量子力学的知识点进行归纳汇总,为之后磁矢量与积算符的引入打下数学物理基础。而之后的第二部分,则从核磁共振中的自旋现象出发,首先引入核磁自旋的唯象模型,随后指出唯象模型在面对部分分子体系时,缺乏坚实可信,且易于理解的诠释,因此,采用类似于角动量算符形式的积算符,来描述磁矢量随外磁场与射频脉冲的变化,也就变得顺理成章。最后的第三部分,笔者主要结合一些常见的核磁脉冲序列,讲解射频脉冲是如何按一定顺序排列组合,达到测定所需核磁信号的目的。</p><h3 id="I-量子力学预备知识"><a href="#I-量子力学预备知识" class="headerlink" title="I. 量子力学预备知识"></a>I. 量子力学预备知识</h3><h4 id="I-1-量子力学基本假设"><a href="#I-1-量子力学基本假设" class="headerlink" title="[I-1] 量子力学基本假设"></a>[I-1] 量子力学基本假设</h4><blockquote><p>i. 定义与研究对象初始或边界条件完全相同的电子所构成的集合为“<strong>体系</strong>”或“<strong>系综</strong>”,则任意给定体系的<strong>一种确定的状态</strong>,与线性矢量空间中<strong>一束确定的具有相同方向的矢量</strong>相对应,该矢量称为体系相应状态的<strong>态矢量</strong>,简称<strong>态矢</strong>;<br>ii. 体系的<strong>物理可观测量</strong>对应于一定的<strong>厄米算符</strong>,该算符的<strong>本征矢</strong>构成相应线性空间的<strong>完备基组</strong>;<br>iii. (<strong>哥本哈根诠释</strong>)对体系的一个物理状态$| u \rangle$,若用算符$\hat{A}$进行测量,则将得到$\hat{A}$的某个本征值$a_i$,并使原来的状态$| u \rangle$投影为$| a_i \rangle$,这一事件发生的概率为$P_i=\big| \langle a_i | u \rangle \big|^2$;<br>iv. (<strong>对易关系</strong>)位置算符与动量算符间的基本对易关系为$[\hat{r}_i,\hat{p}_j]=\delta_{ij} \mathrm{i} \hbar \; (i,j=x,y,z)$,其中$\delta_{ij}$为<strong>克罗内克记号</strong>.</p></blockquote><h4 id="I-2-量子力学的两种基本算符——位置算符和动量算符"><a href="#I-2-量子力学的两种基本算符——位置算符和动量算符" class="headerlink" title="[I-2] 量子力学的两种基本算符——位置算符和动量算符"></a>[I-2] 量子力学的两种基本算符——位置算符和动量算符</h4><p>在经典图景下,任意物体的运动状态均具有两种描述量——<strong>位置</strong>和<strong>速度(或动量)</strong>,且两者可同时确定。考虑到量子力学必须在体系大小渐近至宏观时,收敛为牛顿力学,因此,量子力学中也应该有位置算符和动量算符,且在经典极限下过渡为牛顿力学的表示方式。</p><p>根据量子力学的基本假设i,一维几何空间中粒子的位置$x$对应于态矢$| x \rangle$,而根据基本假设ii,存在位置算符$\hat{x}$,满足$\hat{x} | x \rangle=x | x \rangle$。这样,我们可以将一维几何空间中的任意态矢$| u \rangle$,用位置基矢$| x \rangle$展开,得</p><script type="math/tex; mode=display">| u \rangle=\int^{+\infty}_{-\infty} | x \rangle \langle x | u \rangle dx</script><p>记$\psi(x)=\langle x | u \rangle$,该函数即为位置空间下的波函数,按照基本假设iii,体系处于$x$附近的$dx$区域内的概率为</p><script type="math/tex; mode=display">P(x) dx=\big| \langle x | u \rangle \big|^2 dx=\psi^{*}(x) \psi(x) dx</script><p>特别的,若$| u \rangle$为位置空间的另一基矢$| x’ \rangle$,则用位置基矢$| x \rangle$展开,将变为</p><script type="math/tex; mode=display">| x' \rangle=\int^{+\infty}_{-\infty} | x \rangle \langle x | x' \rangle dx=\int^{+\infty}_{-\infty} | x \rangle \delta(x'-x) dx</script><p>上述的$\delta(x’-x)$为狄拉克delta函数,可认为是连续谱的克罗内克记号,其满足以下性质:</p><blockquote><p>i. $\int^{+\infty}_{-\infty} \delta(x) dx=1$;<br>ii. $x \neq 0$时,$\delta(x)=0$;<br>iii. $\int^{+\infty}_{-\infty} f(x) \delta(x-a) dx=f(a)$;<br><strong>证明</strong>:$\int^{+\infty}_{-\infty} f(x) \delta(x-a) dx=\int^{a+\epsilon}_{a-\epsilon} f(x) \delta(x-a) dx=f(a_0) \int^{a+\epsilon}_{a-\epsilon} \delta(x-a) dx=f(a_0)$,其中$a-\epsilon \leq a_0 \leq a+\epsilon$,当$\epsilon \rightarrow 0$时,$f(a_0) \rightarrow f(a)$,证毕.<br>证明中的第一个等号利用性质ii,第二个等号利用积分中值定理,第三个等号利用性质i.<br>iv. $\delta(ax)=\frac{\delta(x)}{|a|} \; (a \neq 0)$,特别的,$a=-1$时,有$\delta(x)=\delta(-x)$,即delta函数为偶函数;<br><strong>证明</strong>:$a>0$时,由性质iii得</p><script type="math/tex; mode=display">\scriptsize \int^{+\infty}_{-\infty} f(x) \delta(x) dx=f(0) \\ \scriptsize \int^{+\infty}_{-\infty} f(x) \delta(ax) dx=\int^{+\infty}_{-\infty} \frac{f(ax)}{a} \delta(ax) d(ax)=\frac{f(0)}{a}</script><p>比较两式得$\int^{+\infty}_{-\infty} f(x) \delta(x) dx=\int^{+\infty}_{-\infty} f(x) \frac{\delta(ax)}{a} dx$,即$\delta(ax)=\frac{\delta(x)}{a}$;<br>$a<0$时,同理可得</p><script type="math/tex; mode=display">\scriptsize \int^{+\infty}_{-\infty} f(x) \delta(ax) dx=\int^{-\infty}_{+\infty} \frac{f(ax)}{a} \delta(ax) d(ax)=-\frac{f(0)}{a}</script><p>比较两式得$\int^{+\infty}_{-\infty} f(x) \delta(x) dx=\int^{+\infty}_{-\infty} f(x) \big[ -\frac{\delta(ax)}{a} \big] dx$,即$\delta(ax)=-\frac{\delta(x)}{a}$;<br>综上,$\delta(ax)=\frac{\delta(x)}{|a|} \; (a \neq 0)$,证毕;</p></blockquote><p>类似的,一维几何空间中粒子的动量$p$对应于态矢$| p \rangle$,并有相应的算符$\hat{p}$,使$\hat{p} | p \rangle=p | p \rangle$。仿照位置空间的结论,我们有</p><script type="math/tex; mode=display">| u \rangle=\int^{+\infty}_{-\infty} | p \rangle \langle p | u \rangle dp=\int^{+\infty}_{-\infty} | p \rangle \varphi(p) dp \\ P(p) dp=\big| \langle p | u \rangle \big|^2 dp=\varphi^{*}(p) \varphi(p) dp \\ | p' \rangle=\int^{+\infty}_{-\infty} | p \rangle \langle p | p' \rangle dp=\int^{+\infty}_{-\infty} | p \rangle \delta(p'-p) dp</script><h4 id="I-3-量子力学的平移算符"><a href="#I-3-量子力学的平移算符" class="headerlink" title="[I-3] 量子力学的平移算符"></a>[I-3] 量子力学的平移算符</h4><p>通常,我们更喜欢在位置空间(而非动量空间)下描述微观粒子的状态,因此常见的做法是将位置空间变换到坐标空间,同时将动量算符表述为适用于位置空间的形式。</p><p>为此,我们首先引入位移算符,以描述位置空间中坐标的变化。设任意维度位置空间中,有一态矢$| \boldsymbol{r} \rangle$,其平移任意一段无穷小的距离$d \boldsymbol{s}$后,变为另一态矢$| \boldsymbol{r}+d \boldsymbol{s} \rangle$,这一过程对应于一个算符,记为$\hat{D}(d \boldsymbol{s})$,对应的变换过程为$| \boldsymbol{r} \rangle \rightarrow | \boldsymbol{r}+d \boldsymbol{s} \rangle=\hat{D}(d \boldsymbol{s})| \boldsymbol{r} \rangle$。此时有:</p><script type="math/tex; mode=display">\begin{align}\hat{\boldsymbol{r}} \hat{D}(d \boldsymbol{s}) | \boldsymbol{r} \rangle &= \hat{\boldsymbol{r}} | \boldsymbol{r}+d \boldsymbol{s} \rangle=(\boldsymbol{r}+d \boldsymbol{s}) | \boldsymbol{r}+d \boldsymbol{s} \rangle \\\hat{D}(d \boldsymbol{s}) \hat{\boldsymbol{r}} | \boldsymbol{r} \rangle &= \hat{D}(d \boldsymbol{s}) (\boldsymbol{r} | \boldsymbol{r} \rangle)=\boldsymbol{r} \hat{D}(d \boldsymbol{s}) | \boldsymbol{r} \rangle=\boldsymbol{r} | \boldsymbol{r}+d \boldsymbol{s} \rangle \\[\hat{\boldsymbol{r}}, \hat{D}(d \boldsymbol{s})] | \boldsymbol{r} \rangle &= [\hat{\boldsymbol{r}} \hat{D}(d \boldsymbol{s})-\hat{D}(d \boldsymbol{s}) \hat{\boldsymbol{r}}] | \boldsymbol{r} \rangle=d \boldsymbol{s} | \boldsymbol{r}+d \boldsymbol{s} \rangle \simeq d \boldsymbol{s} | \boldsymbol{r} \rangle\end{align}</script><p>故$[\hat{\boldsymbol{r}}, \hat{D}(d \boldsymbol{s})]=d \boldsymbol{s}$,此外,由平移的物理意义,我们希望位移算符$\hat{D}(d \boldsymbol{s})$具备以下性质:</p><blockquote><p>i. $\hat{D}(d \boldsymbol{s})$<strong>不影响态矢的内积</strong>,即对任意$| \boldsymbol{r}_1\rangle$和$| \boldsymbol{r}_2 \rangle$,在平移$d \boldsymbol{s}$,变为$| \boldsymbol{r}_1^{‘} \rangle=\hat{D}(d \boldsymbol{s}) | \boldsymbol{r}_1 \rangle$和$| \boldsymbol{r}_2^{‘} \rangle=\hat{D}(d \boldsymbol{s}) | \boldsymbol{r}_2 \rangle$后,有$\langle \boldsymbol{r}_1^{‘} | \boldsymbol{r}_2^{‘} \rangle=\langle \boldsymbol{r}_1 | \hat{D}^{\dagger}(d \boldsymbol{s}) \hat{D}(d \boldsymbol{s}) | \boldsymbol{r}_2 \rangle=\langle \boldsymbol{r}_1 | \boldsymbol{r}_2 \rangle$;<br><strong>推论i</strong>. $\hat{D}^{\dagger}(d \boldsymbol{s}) \hat{D}(d \boldsymbol{s})=\hat{I}$,即$\hat{D}(d \boldsymbol{s})$具有<strong>幺正性</strong>;<br>ii.(<strong>平移可加性</strong>)任意连续的平移操作$\hat{D}(d \boldsymbol{s}_1)$和$\hat{D}(d \boldsymbol{s}_2)$,等价于一次总平移为$d \boldsymbol{s}_1+d \boldsymbol{s}_2$的平移操作,即$\hat{D}(d \boldsymbol{s}_2) \hat{D}(d \boldsymbol{s}_1)=\hat{D}(d \boldsymbol{s}_1+d \boldsymbol{s}_2)$;<br>iii. (<strong>平移逆操作定义</strong>)平移的逆操作等同于沿相反方向的平移操作,即$\hat{D}^{-1}(d \boldsymbol{s})=\hat{D}(-d \boldsymbol{s})$;<br>iv. 当$d \boldsymbol{s}$趋近于0,$\hat{D}(d \boldsymbol{s})$趋近于单位算符$\hat{I}$.</p></blockquote><p>容易验证,若取$\hat{D}(d \boldsymbol{s})=\hat{I}-\mathrm{i} \hat{\boldsymbol{K}} \cdot d \boldsymbol{s}$($\hat{\boldsymbol{K}}$为厄米算符),并忽略高阶无穷小项,则上述性质均可满足,此时代入位移算符与坐标算符的对易关系,得</p><script type="math/tex; mode=display">\begin{align}[\hat{\boldsymbol{r}}, \hat{D}(d \boldsymbol{s})] &= \hat{\boldsymbol{r}} \hat{D}(d \boldsymbol{s})-\hat{D}(d \boldsymbol{s}) \hat{\boldsymbol{r}}=\hat{\boldsymbol{r}} (\hat{I}-\mathrm{i} \hat{\boldsymbol{K}} \cdot d \boldsymbol{s})-(\hat{I}-\mathrm{i} \hat{\boldsymbol{K}} \cdot d \boldsymbol{s}) \hat{\boldsymbol{r}} \\ &= -\mathrm{i} \big[ \hat{\boldsymbol{r}} (\hat{\boldsymbol{K}} \cdot d \boldsymbol{s})-(\hat{\boldsymbol{K}} \cdot d \boldsymbol{s}) \hat{\boldsymbol{r}} \big]=d \boldsymbol{s}\end{align}</script><p>由于无穷小量的方向任意,因此可以令$d \boldsymbol{s}$取向与某一坐标轴重合,即$d \boldsymbol{s}=ds \boldsymbol{e}_j$,此时$\hat{\boldsymbol{K}} \cdot d \boldsymbol{s}=\hat{K}_j ds$。另一方面,将坐标算符展开,得$\hat{\boldsymbol{r}}=\sum\limits_{i=1}^{n} \hat{r}_i \boldsymbol{e}_i$,代入上式,得</p><script type="math/tex; mode=display">-\mathrm{i} \big[ (\sum\limits_{i=1}^{n} \hat{r}_i \boldsymbol{e}_i) \hat{K}_j ds-\hat{K}_j ds (\sum\limits_{i=1}^{n} \hat{r}_i \boldsymbol{e}_i) \big]=\sum\limits_{i=1}^{n} (-\mathrm{i} ds \boldsymbol{e}_i) (\hat{r}_i \hat{K}_j-\hat{K}_j \hat{r}_i)=ds \boldsymbol{e}_j</script><p>比较左右两边可知$-\mathrm{i} [\hat{r}_i,\hat{K}_j]=\delta_{ij}$,或写作$[\hat{r}_i,\hat{K}_j]=\mathrm{i} \delta_{ij}$,再比照基本对易关系,得$\hat{K}_j=\frac{\hat{p}_j}{\hbar}$,从而平移算符表示为$\hat{D}(d \boldsymbol{s})=\hat{I}-\frac{\mathrm{i}}{\hbar} \hat{\boldsymbol{p}} \cdot d \boldsymbol{s}$。</p><p>如果位移算符作用长度不是无穷小量$d \boldsymbol{s}$,而是一段有穷长度$\boldsymbol{s}$,那么平移算符将变为</p><script type="math/tex; mode=display">\hat{D}(\boldsymbol{s})=\lim_{n \rightarrow \infty} (\hat{I}-\frac{\mathrm{i}}{\hbar} \hat{\boldsymbol{p}} \cdot \frac{\boldsymbol{s}}{n})^{n}=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{\boldsymbol{p}} \cdot \boldsymbol{s}}</script><p>有了位移算符,我们就可以在位置表象中描述动量算符。首先,将位移算符作用于任意态矢$| u \rangle$,得$\hat{D}(d \boldsymbol{s}) | u \rangle=(\hat{I}-\frac{\mathrm{i}}{\hbar} \hat{\boldsymbol{p}} \cdot d \boldsymbol{s}) | u \rangle$,随后左乘$\langle \boldsymbol{r} |$,变为</p><script type="math/tex; mode=display">\begin{align}\mathrm{left} &= \langle \boldsymbol{r} | \hat{D}(d \boldsymbol{s}) | u \rangle=\langle u | \hat{D}^{\dagger}(d \boldsymbol{s}) | \boldsymbol{r} \rangle^{*}=\langle u | \hat{D}^{-1}(d \boldsymbol{s}) | \boldsymbol{r} \rangle^{*} \\ &=\langle u | \hat{D}(-d \boldsymbol{s}) | \boldsymbol{r} \rangle^{*}=\langle u | \boldsymbol{r}-d \boldsymbol{s} \rangle^{*}=\langle \boldsymbol{r}-d \boldsymbol{s} | u \rangle \\\mathrm{right} &= \langle \boldsymbol{r} | (\hat{I}-\frac{\mathrm{i}}{\hbar} \hat{\boldsymbol{p}} \cdot d \boldsymbol{s}) | u \rangle=\langle \boldsymbol{r} | u \rangle-\frac{\mathrm{i}}{\hbar} \langle \boldsymbol{r} | \hat{\boldsymbol{p}} | u \rangle \cdot d \boldsymbol{s}\end{align}</script><p>左式即为波函数$\psi(\boldsymbol{r}-d \boldsymbol{s})$,其泰勒展开为$\psi(\boldsymbol{r}-d \boldsymbol{s})=\psi(\boldsymbol{r})+\sum\limits_{i=1}^{\infty} \frac{\partial^{i} \psi}{\partial \boldsymbol{r}^{i}} (-d \boldsymbol{s})^{i}$,截断到一次项,并记$\nabla_{\boldsymbol{r}}=\frac{\partial}{\partial \boldsymbol{r}}$,得</p><script type="math/tex; mode=display">\psi(\boldsymbol{r}-d \boldsymbol{s}) \simeq \psi(\boldsymbol{r})-\nabla_{\boldsymbol{r}} \psi(\boldsymbol{r}) \cdot d \boldsymbol{s}=\langle \boldsymbol{r} | u \rangle-\nabla_{\boldsymbol{r}} \langle \boldsymbol{r} | u \rangle \cdot d \boldsymbol{s}=\langle \boldsymbol{r} | u \rangle-\frac{\mathrm{i}}{\hbar} \langle \boldsymbol{r} | \hat{\boldsymbol{p}} | u \rangle \cdot d \boldsymbol{s}</script><p>故$\nabla_{\boldsymbol{r}} \langle \boldsymbol{r} | u \rangle=\frac{\mathrm{i}}{\hbar} \langle \boldsymbol{r} | \hat{\boldsymbol{p}} | u \rangle$,即$\langle \boldsymbol{r} | \hat{\boldsymbol{p}} | u \rangle=-\mathrm{i} \hbar \nabla_{\boldsymbol{r}} \langle \boldsymbol{r} | u \rangle$。从而在位置表象中,动量算符即为$\hat{\boldsymbol{p}}=-\mathrm{i} \hbar \nabla_{\boldsymbol{r}}$,该表达式仅在直角坐标系中成立。</p><h4 id="I-4-位置空间与动量空间的转换"><a href="#I-4-位置空间与动量空间的转换" class="headerlink" title="[I-4] 位置空间与动量空间的转换"></a>[I-4] 位置空间与动量空间的转换</h4><p>有了动量算符在位置表象的表示,我们可以将位置空间与动量空间的波函数进行相互转换:</p><script type="math/tex; mode=display">\varphi(\boldsymbol{p})=\langle \boldsymbol{p} | u \rangle=\int \langle \boldsymbol{p} | \boldsymbol{r} \rangle d \boldsymbol{r} \langle \boldsymbol{r} | u \rangle=\int \langle \boldsymbol{p} | \boldsymbol{r} \rangle d^{n}r \langle \boldsymbol{r} | u \rangle \\ \psi(\boldsymbol{r})=\langle \boldsymbol{r} | u \rangle=\int \langle \boldsymbol{r} | \boldsymbol{p} \rangle d \boldsymbol{p} \langle \boldsymbol{p} | u \rangle=\int \langle \boldsymbol{r} | \boldsymbol{p} \rangle d^{n}p \langle \boldsymbol{p} | u \rangle</script><p>然而,上述转换式中出现了未知量$\langle \boldsymbol{p} | \boldsymbol{r} \rangle$和$\langle \boldsymbol{r} | \boldsymbol{p} \rangle$,这是我们亟待解决的,为此,我们考虑动量算符作用在动量态矢的表达式$\hat{\boldsymbol{p}} | \boldsymbol{p} \rangle=\boldsymbol{p} | \boldsymbol{p} \rangle$,左乘$\langle \boldsymbol{r} |$得$\langle \boldsymbol{r} | \hat{\boldsymbol{p}} | \boldsymbol{p} \rangle=-\mathrm{i} \hbar \nabla_{\boldsymbol{r}} \langle \boldsymbol{r} | \boldsymbol{p} \rangle=\boldsymbol{p} \langle \boldsymbol{r} | \boldsymbol{p} \rangle$,这是一个自变量为$\boldsymbol{r}$的微分方程,故</p><script type="math/tex; mode=display">-\mathrm{i} \hbar \nabla_{\boldsymbol{r}} \langle \boldsymbol{r} | \boldsymbol{p} \rangle=\boldsymbol{p} \langle \boldsymbol{r} | \boldsymbol{p} \rangle \; \Rightarrow \; \frac{\partial \langle \boldsymbol{r} | \boldsymbol{p} \rangle}{\langle \boldsymbol{r} | \boldsymbol{p} \rangle}=\frac{\mathrm{i} \boldsymbol{p}}{\hbar} \partial \boldsymbol{r} \; \Rightarrow \; \ln{\frac{\langle \boldsymbol{r} | \boldsymbol{p} \rangle}{A}}=\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar} \; \Rightarrow \; \langle \boldsymbol{r} | \boldsymbol{p} \rangle=A \mathrm{e}^{\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}} (A \in \mathbb{C})</script><p>根据动量空间基矢的正交归一条件,我们有</p><script type="math/tex; mode=display">\begin{align}\delta^{n}(\boldsymbol{p}'-\boldsymbol{p}) &= \langle \boldsymbol{p}' | \boldsymbol{p} \rangle=\int \langle \boldsymbol{p}' | \boldsymbol{r} \rangle d^{n}r \langle \boldsymbol{r} | \boldsymbol{p} \rangle=\int A^{*} \mathrm{e}^{-\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}} \cdot A \mathrm{e}^{\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}} d^{n}r \\ &= \big| A \big|^2 \int \mathrm{e}^{\frac{\mathrm{i} (\boldsymbol{p}-\boldsymbol{p}') \cdot \boldsymbol{r}}{\hbar}} d^{n}r=\big| A \big|^2 (2 \pi \hbar)^n \cdot \frac{1}{(2 \pi \hbar)^n} \int \mathrm{e}^{\frac{-\mathrm{i} (\boldsymbol{p}'-\boldsymbol{p}) \cdot \boldsymbol{r}}{\hbar}} d^{n}r \\ &= \big| A \big|^2 (2 \pi \hbar)^n \delta^{n}(\boldsymbol{p}'-\boldsymbol{p})\end{align}</script><p>因此$\big| A \big|=(2 \pi \hbar)^{-\frac{n}{2}}$,若取$A$为实数,则$\langle \boldsymbol{r} | \boldsymbol{p} \rangle=A \mathrm{e}^{\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}}=(2 \pi \hbar)^{-\frac{n}{2}} \mathrm{e}^{\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}}$</p><p>上式的推导过程中,用到狄拉克delta函数的常用表达形式$\delta(q)=\frac{1}{2 \pi} \int^{+\infty}_{-\infty} \mathrm{e}^{-\mathrm{i} kq} dq$,及以直角坐标表示的多维空间中,delta函数与一维空间的delta函数的关系$\delta^{n}(\boldsymbol{q})=\prod\limits_{i=1}^{n} \delta(q_i)$</p><p>这样,位置空间与动量空间的波函数相互转换的表达式,便可以改写为</p><script type="math/tex; mode=display">\varphi(\boldsymbol{p})=\langle \boldsymbol{p} | u \rangle=\int \langle \boldsymbol{p} | \boldsymbol{r} \rangle d^{n}r \langle \boldsymbol{r} | u \rangle=(2 \pi \hbar)^{-\frac{n}{2}} \int \mathrm{e}^{-\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}} \psi(\boldsymbol{r}) d^{n}r \\ \psi(\boldsymbol{r})=\langle \boldsymbol{r} | u \rangle=\int \langle \boldsymbol{r} | \boldsymbol{p} \rangle d^{n}p \langle \boldsymbol{p} | u \rangle=(2 \pi \hbar)^{-\frac{n}{2}} \int \mathrm{e}^{\frac{\mathrm{i} \boldsymbol{p} \cdot \boldsymbol{r}}{\hbar}} \varphi(\boldsymbol{p}) d^{n}p</script><h4 id="I-5-量子力学的角动量算符"><a href="#I-5-量子力学的角动量算符" class="headerlink" title="[I-5] 量子力学的角动量算符"></a>[I-5] 量子力学的角动量算符</h4><p>在经典力学中,三维空间的角动量的定义为$\boldsymbol{L}=\boldsymbol{r} \times \boldsymbol{p}$,其中$\boldsymbol{r}$为圆周运动时圆心到物体的位置矢量,$\boldsymbol{p}$为物体做圆周运动时的动量。而在量子力学中,三维空间的角动量算符的定义与经典力学相近:$\hat{\boldsymbol{L}}=\hat{\boldsymbol{r}} \times \hat{\boldsymbol{p}}$——仅仅将位置和动量用对应的算符替代而已。</p><p>根据[I-5]节的介绍,在直角坐标系中,动量算符于位置空间的表达式为$\hat{\boldsymbol{p}}=-\mathrm{i} \hbar \nabla_{\boldsymbol{r}}$,对应于每一维,则有$\hat{p}_i=-\mathrm{i} \hbar \nabla_{r_i}$,将其代入角动量算符的定义,可得</p><script type="math/tex; mode=display">\hat{\boldsymbol{L}}=\hat{\boldsymbol{r}} \times \hat{\boldsymbol{p}}=-\mathrm{i} \hbar \begin{vmatrix} \boldsymbol{e}_x & \boldsymbol{e}_y & \boldsymbol{e}_z \\ \hat{x} & \hat{y} & \hat{z} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \end{vmatrix}=-\mathrm{i} \hbar \big[ (\hat{y} \frac{\partial}{\partial z}-\hat{z} \frac{\partial}{\partial y}) \boldsymbol{e}_x+(\hat{z} \frac{\partial}{\partial x}-\hat{x} \frac{\partial}{\partial z}) \boldsymbol{e}_y+(\hat{x} \frac{\partial}{\partial y}-\hat{y} \frac{\partial}{\partial x}) \boldsymbol{e}_z \big]</script><p>从而角动量在各维度的分量为</p><script type="math/tex; mode=display">\hat{L}_x=-\mathrm{i} \hbar (\hat{y} \frac{\partial}{\partial z}-\hat{z} \frac{\partial}{\partial y}) \quad \hat{L}_y=-\mathrm{i} \hbar (\hat{z} \frac{\partial}{\partial x}-\hat{x} \frac{\partial}{\partial z}) \quad \hat{L}_z=-\mathrm{i} \hbar (\hat{x} \frac{\partial}{\partial y}-\hat{y} \frac{\partial}{\partial x})</script><p>当维度数不为3时,叉积无良性定义,因此角动量算符需改写为$\hat{\boldsymbol{L}}=\hat{\boldsymbol{r}} \wedge \hat{\boldsymbol{p}}$,其中$\wedge$为楔积符号,满足下列性质:</p><blockquote><p>i. (<strong>结合律</strong>)对任意向量$\boldsymbol{a}$, $\boldsymbol{b}$和$\boldsymbol{c}$,有$(\boldsymbol{a} \wedge \boldsymbol{b}) \wedge \boldsymbol{c}=\boldsymbol{a} \wedge (\boldsymbol{b} \wedge \boldsymbol{c})$<br>ii. (<strong>线性</strong>)设$k_1$与$k_2$为任意常数,对任意向量$\boldsymbol{a}_1$, $\boldsymbol{a}_2$和$\boldsymbol{b}$,有</p><script type="math/tex; mode=display">\scriptsize (k_1 \boldsymbol{a}_1+k_2 \boldsymbol{a}_2) \wedge \boldsymbol{b}=k_1 (\boldsymbol{a}_1 \wedge \boldsymbol{b})+k_2 (\boldsymbol{a}_2 \wedge \boldsymbol{b}) \\ \scriptsize (k_1 \boldsymbol{a}_1+k_2 \boldsymbol{a}_2) \wedge \boldsymbol{b}=k_1 (\boldsymbol{a}_1 \wedge \boldsymbol{b})+k_2 (\boldsymbol{a}_2 \wedge \boldsymbol{b})</script><p>iii. (<strong>交换/反交换律</strong>)对任意向量$\boldsymbol{a}$和$\boldsymbol{b}$,若其维度数为$p$与$q$,则$\boldsymbol{a} \wedge \boldsymbol{b}=(-1)^{pq} (\boldsymbol{b} \wedge \boldsymbol{a})$</p></blockquote><p>由此,我们可以推出其他维度中角动量算符的表达式:</p><script type="math/tex; mode=display">\begin{align}\hat{\boldsymbol{L}} &= \hat{\boldsymbol{r}} \wedge \hat{\boldsymbol{p}}=(\sum\limits_{i=1}^{n} \hat{r}_i \boldsymbol{e}_i) \wedge (\sum\limits_{i=1}^{n} \hat{p}_i \boldsymbol{e}_i)=\sum\limits_{\substack{1 \leq i<j \leq n \\ i \neq j}} (\hat{r}_i \hat{p}_j-\hat{r}_j \hat{p}_i) (\boldsymbol{e}_i \wedge \boldsymbol{e}_j) \\ &= -\mathrm{i} \hbar \sum\limits_{\substack{1 \leq i<j \leq n \\ i \neq j}} (\hat{r}_i \frac{\partial}{\partial r_j}-\hat{r}_j \frac{\partial}{\partial r_i}) (\boldsymbol{e}_i \wedge \boldsymbol{e}_j)\end{align}</script><p>从而角动量在各维度的分量为$\hat{L}_{ij}=\hat{r}_i \frac{\partial}{\partial r_j}-\hat{r}_j \frac{\partial}{\partial r_i}$,其中下标$[ij]$表示转动平面由坐标轴$i$与坐标轴$j$构成,且从坐标轴$i$转向坐标轴$j$。显然,三维空间的角动量算符是上述定义的特例,因</p><script type="math/tex; mode=display">\begin{align}\hat{\boldsymbol{L}} &= -\mathrm{i} \hbar \Big[ (\hat{y} \frac{\partial}{\partial z}-\hat{z} \frac{\partial}{\partial y}) (\boldsymbol{e}_y \wedge \boldsymbol{e}_z)+(\hat{z} \frac{\partial}{\partial x}-\hat{x} \frac{\partial}{\partial z}) (\boldsymbol{e}_z \wedge \boldsymbol{e}_x)+(\hat{x} \frac{\partial}{\partial y}-\hat{y} \frac{\partial}{\partial x}) (\boldsymbol{e}_x \wedge \boldsymbol{e}_y) \Big] \\&= -\mathrm{i} \hbar \Big[ \begin{vmatrix} \hat{y} & \hat{z} \\ \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \end{vmatrix} (\boldsymbol{e}_y \wedge \boldsymbol{e}_z)-\begin{vmatrix} \hat{x} & \hat{z} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial z} \end{vmatrix} (\boldsymbol{e}_z \wedge \boldsymbol{e}_x)+\begin{vmatrix} \hat{x} & \hat{y} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} \end{vmatrix} (\boldsymbol{e}_x \wedge \boldsymbol{e}_y) \Big] \\ &= -\mathrm{i} \hbar \begin{vmatrix} \boldsymbol{e}_y \wedge \boldsymbol{e}_z & \boldsymbol{e}_z \wedge \boldsymbol{e}_x & \boldsymbol{e}_x \wedge \boldsymbol{e}_y \\ \hat{x} & \hat{y} & \hat{z} \\ \frac{\partial}{\partial x} & \frac{\partial}{\partial y} & \frac{\partial}{\partial z} \end{vmatrix}\end{align}</script><p>比照用叉积定义的角动量算符,有$\boldsymbol{e}_x=\boldsymbol{e}_y \wedge \boldsymbol{e}_z$, $\boldsymbol{e}_y=\boldsymbol{e}_z \wedge \boldsymbol{e}_x$, $\boldsymbol{e}_z=\boldsymbol{e}_x \wedge \boldsymbol{e}_y$,均满足右手定则的定义。在接下来的篇幅中,我们将着重讨论三维空间下的角动量算符,而不再深入探讨其余维度数的情形。</p><p>依照角动量在各维度分量的表达式,我们有如下推论:</p><blockquote><p>i. $[\hat{L}_i, \hat{L}_j]=\mathrm{i} \hbar \sum\limits_{k=x,y,z} \varepsilon_{ijk} \hat{L}_k$,其中$\varepsilon_{ijk}$为Levi-Civita记号,当下标$[ijk]$中有任意两数相同时,$\varepsilon_{ijk}=0$;当下标$[ijk]=[xyz],[yzx],[zxy]$时,$\varepsilon_{ijk}=1$;当下标$[ijk]=[zyx],[yxz],[xzy]$时,$\varepsilon_{ijk}=-1$;<br><strong>证明</strong>:以$[\hat{L}_x, \hat{L}_y]=\mathrm{i} \hbar \hat{L}_z$为例,因$\hat{L}_{x}=\hat{y} \hat{p}_z-\hat{z} \hat{p}_y$,$\hat{L}_{y}=\hat{z} \hat{p}_x-\hat{x} \hat{p}_z$,故</p><script type="math/tex; mode=display">\scriptsize\begin{align}[\hat{L}_x, \hat{L}_y] &= [\hat{y} \hat{p}_z-\hat{z} \hat{p}_y, \hat{z} \hat{p}_x-\hat{x} \hat{p}_z]=[\hat{y} \hat{p}_z, \hat{z} \hat{p}_x-\hat{x} \hat{p}_z]-[\hat{z} \hat{p}_y, \hat{z} \hat{p}_x-\hat{x} \hat{p}_z] \\&= [\hat{y} \hat{p}_z, \hat{z} \hat{p}_x]-[\hat{y} \hat{p}_z, \hat{x} \hat{p}_z]-[\hat{z} \hat{p}_y, \hat{z} \hat{p}_x]+[\hat{z} \hat{p}_y, \hat{x} \hat{p}_z] \\&= \hat{y} [\hat{p}_z,\hat{z} \hat{p}_x]+[\hat{y},\hat{z} \hat{p}_x] \hat{p}_z-\hat{y} [\hat{p}_z,\hat{x} \hat{p}_z]-[\hat{y},\hat{x} \hat{p}_z] \hat{p}_z \\&\quad -\hat{z} [\hat{p}_y, \hat{z} \hat{p}_x]-[\hat{z},\hat{z} \hat{p}_x] \hat{p}_y+\hat{z} [\hat{p}_y,\hat{x} \hat{p}_z]+[\hat{z},\hat{x} \hat{p}_z] \hat{p}_y \\ &= \hat{y}[\hat{p}_z,\hat{z}] \hat{p}_x+\hat{x} [\hat{z},\hat{p}_z] \hat{p}_y=\mathrm{i} \hbar (\hat{x} \hat{p}_y-\hat{y} \hat{p}_x)=\mathrm{i} \hbar \hat{L}_z\end{align}</script><p>其余情形可仿照上述推导过程加以证明;<br>ii. $[\hat{L}_i, \hat{r}_j]=\mathrm{i} \hbar \sum\limits_{k=x,y,z} \varepsilon_{ijk} \hat{r}_k$;<br><strong>证明</strong>:以$[\hat{L}_x, \hat{y}]=\mathrm{i} \hbar \hat{z}$为例,显然</p><script type="math/tex; mode=display">\scriptsize\begin{align}[\hat{L}_x, \hat{y}] &= [\hat{y} \hat{p}_z-\hat{z} \hat{p}_y,\hat{y}]=[\hat{y} \hat{p}_z,\hat{y}]-[\hat{z} \hat{p}_y,\hat{y}] \\ &= \hat{y} [\hat{p}_z,\hat{y}]+[\hat{y},\hat{y}] \hat{p}_z-\hat{z} [\hat{p}_y,\hat{y}]-[\hat{z},\hat{y}] \hat{p}_y =\mathrm{i} \hbar \hat{z}\end{align}</script><p>其余情形可仿照上述推导过程加以证明;<br>iii. $[\hat{L}_i, \hat{p}_j]=\mathrm{i} \hbar \sum\limits_{k=x,y,z} \varepsilon_{ijk} \hat{p}_k$;<br><strong>证明</strong>:以$[\hat{L}_x, \hat{p}_y]=\mathrm{i} \hbar \hat{p}_z$为例,显然</p><script type="math/tex; mode=display">\scriptsize\begin{align}[\hat{L}_x, \hat{y}] &= [\hat{y} \hat{p}_z-\hat{z} \hat{p}_y,\hat{p}_y]=[\hat{y} \hat{p}_z,\hat{p}_y]-[\hat{z} \hat{p}_y,\hat{p}_y] \\ &= \hat{y} [\hat{p}_z,\hat{p}_y]+[\hat{y},\hat{p}_y] \hat{p}_z-\hat{z} [\hat{p}_y,\hat{p}_y]-[\hat{z},\hat{p}_y] \hat{p}_y =\mathrm{i} \hbar \hat{p}_z\end{align}</script><p>其余情形可仿照上述推导过程加以证明;<br>iv. (<strong>角动量平方算符性质</strong>)定义角动量平方算符$\hat{L}^2=\hat{\boldsymbol{L}} \cdot \hat{\boldsymbol{L}}=\hat{L}_x^2+\hat{L}_y^2+\hat{L}_z^2$,则有$[\hat{L}^2,\hat{L}_k]=0 \; (k=x,y,z)$;<br><strong>证明</strong>:以$[\hat{L}^2,\hat{L}_x]=0$为例,利用推论i,我们有</p><script type="math/tex; mode=display">\scriptsize\begin{align}[\hat{L}^2,\hat{L}_x] &= [\hat{L}_x^2+\hat{L}_y^2+\hat{L}_z^2,\hat{L}_x]=[\hat{L}_x^2,\hat{L}_x]+[\hat{L}_y^2,\hat{L}_x]+[\hat{L}_z^2,\hat{L}_x] \\ &= \hat{L}_y [\hat{L}_y,\hat{L}_x]+[\hat{L}_y,\hat{L}_x] \hat{L}_y+\hat{L}_z [\hat{L}_z,\hat{L}_x]+[\hat{L}_z,\hat{L}_x] \hat{L}_z \\ &= -\mathrm{i} \hbar \hat{L}_y \hat{L}_z-\mathrm{i} \hbar \hat{L}_z \hat{L}_y+\mathrm{i} \hbar \hat{L}_z \hat{L}_y+\mathrm{i} \hbar \hat{L}_y \hat{L}_z=0\end{align}</script><p>其余情形可仿照上述推导过程加以证明;<br>v. (<strong>上升/下降算符性质</strong>)定义角动量上升算符$\hat{L}_{+}=\hat{L}_x+\mathrm{i} \hat{L}_y$,以及下降算符$\hat{L}_{-}=\hat{L}_x-\mathrm{i} \hat{L}_y$,则有(a) $[\hat{L}_z,\hat{L}_{\pm}]=\pm \hbar \hat{L}_{\pm}$; (b) $[\hat{L}^2,\hat{L}_{\pm}]=0$; (c) $[\hat{L}_{+},\hat{L}_{-}]=2 \hbar \hat{L}_z$;<br><strong>证明</strong>:(a) 利用推论i,我们有</p><script type="math/tex; mode=display">\scriptsize\begin{align} [\hat{L}_z,\hat{L}_{\pm}] &= [\hat{L}_z,\hat{L}_x \pm \mathrm{i} \hat{L}_y]=[\hat{L}_z,\hat{L}_x] \pm \mathrm{i} [\hat{L}_z,\hat{L}_y] \\ &=\mathrm{i} \hbar \hat{L}_y \pm \mathrm{i} \cdot (-\mathrm{i} \hbar \hat{L}_x)=\pm \hbar (\hat{L}_x \pm \mathrm{i} \hat{L}_y)=\pm \hbar \hat{L}_{\pm}\end{align}</script><p>(b) 利用推论iv,我们有$[\hat{L}^2,\hat{L}_{\pm}]=[\hat{L}^2,\hat{L}_x \pm \mathrm{i} \hat{L}_y]=[\hat{L}^2,\hat{L}_x] \pm \mathrm{i} [\hat{L}^2,\hat{L}_y]=0$<br>(c) 利用推论i,我们有</p><script type="math/tex; mode=display">\scriptsize\begin{align}[\hat{L}_{+},\hat{L}_{-}] &= [\hat{L}_x+\mathrm{i} \hat{L}_y,\hat{L}_x-\mathrm{i} \hat{L}_y] \\ &= [\hat{L}_x,\hat{L}_x]+\mathrm{i} [\hat{L}_y,\hat{L}_x]-\mathrm{i} [\hat{L}_x,\hat{L}_y]+[\hat{L}_y,\hat{L}_y] \\ &= \mathrm{i} \cdot (-\mathrm{i} \hbar \hat{L}_z)-\mathrm{i} \cdot \mathrm{i} \hbar \hat{L}_z=2 \hbar \hat{L}_z\end{align}</script></blockquote><h4 id="I-6-角动量算符的本征态与本征值"><a href="#I-6-角动量算符的本征态与本征值" class="headerlink" title="[I-6] 角动量算符的本征态与本征值"></a>[I-6] 角动量算符的本征态与本征值</h4><p>回顾前一节描述的角动量算符的性质,我们发现$\hat{L}^2$与$\hat{L}_{x}$, $\hat{L}_{y}$, $\hat{L}_{z}$对易(自然,$\hat{L}^2$也与$\hat{L}_{+}$和$\hat{L}_{-}$对易),因此,我们可以用$\hat{L}^2$与角动量算符的其中一个分量$\hat{L}_{z}$的共同本征矢,作为描述相应空间的基矢。将该基矢记为$| ab \rangle$,它满足</p><script type="math/tex; mode=display">\hat{L}^2 | ab \rangle=a | ab \rangle \quad \hat{L}_{z} | ab \rangle=b | ab \rangle</script><p>由于角动量平方算符,以及角动量分量的平方算符的本征值均不小于零,因此</p><script type="math/tex; mode=display">\langle ab | (\hat{L}_x^2+\hat{L}_y^2) | ab \rangle=\langle ab | (\hat{L}^2-\hat{L}_z^2) | ab \rangle=(a-b^2) \langle ab | ab \rangle \geq 0 \cdot \langle ab | ab \rangle</script><p>从而$a-b^2 \geq 0$,即$a \geq b^2$,这表明对给定的$a \geq 0$,必存在$b_{\mathrm{max}}$与$b_{\mathrm{min}}$,使得$-\sqrt{a} \leq b_{\mathrm{min}} \leq b \leq b_{\mathrm{max}} \leq \sqrt{a}$,上述推导用到基矢内积不小于零的性质。</p><p>另一方面,根据上升/下降算符与$\hat{L}^2$和$\hat{L}_{z}$的对易关系,我们有</p><script type="math/tex; mode=display">\hat{L}^2 \hat{L}_{\pm} | ab \rangle=([\hat{L}^2,\hat{L}_{\pm}]+\hat{L}_{\pm} \hat{L}^2) | ab \rangle=0 \cdot | ab \rangle+\hat{L}_{\pm} \hat{L}^2 | ab \rangle=a \hat{L}_{\pm} | ab \rangle \\\hat{L}_z \hat{L}_{\pm} | ab \rangle=([\hat{L}_z,\hat{L}_{\pm}]+\hat{L}_{\pm} \hat{L}_z) | ab \rangle=\pm \hbar \hat{L}_{\pm} | ab \rangle+b \hat{L}_{\pm} | ab \rangle=(b \pm \hbar) \hat{L}_{\pm} | ab \rangle</script><p>因此$\hat{L}_{\pm} | ab \rangle$仍然是$\hat{L}^2$与$\hat{L}_{z}$的本征态,且本征值分别为$a$与$(b \pm \hbar)$,从而有$\hat{L}_{\pm} | ab \rangle=c_{\pm} | a,b \pm \hbar \rangle$,其中$c_{\pm}$为常数。由于$b$存在上下界,因此当上升/下降算符分别作用于$| ab_{\mathrm{max}} \rangle$和$| ab_{\mathrm{min}} \rangle$时,结果为</p><script type="math/tex; mode=display">\begin{cases} \hat{L}_{+} | ab_{\mathrm{max}} \rangle=\boldsymbol{0} \\ \hat{L}_{-} | ab_{\mathrm{min}} \rangle=\boldsymbol{0} \end{cases} \; \Rightarrow \; \begin{cases} \hat{L}_{-} \hat{L}_{+} | ab_{\mathrm{max}} \rangle=\boldsymbol{0} \\ \hat{L}_{+} \hat{L}_{-} | ab_{\mathrm{min}} \rangle=\boldsymbol{0} \end{cases}</script><p>将上升/下降算符展开,得</p><script type="math/tex; mode=display">\begin{align}\hat{L}_{-} \hat{L}_{+} &= (\hat{L}_x-\mathrm{i} \hat{L}_y) (\hat{L}_x+\mathrm{i} \hat{L}_y)=(\hat{L}_x^2+\hat{L}_y^2)+\mathrm{i} (\hat{L}_x \hat{L}_y-\hat{L}_y \hat{L}_x) \\ &= (\hat{L}^2-\hat{L}_z^2)+\mathrm{i} \cdot \mathrm{i} \hbar \hat{L}_z=\hat{L}^2-\hat{L}_z^2-\hbar \hat{L}_z \\\hat{L}_{+} \hat{L}_{-} &= [\hat{L}_{+},\hat{L}_{-}]+\hat{L}_{-} \hat{L}_{+}=2 \hbar \hat{L}_z+(\hat{L}^2-\hat{L}_z^2-\hbar \hat{L}_z)=\hat{L}^2-\hat{L}_z^2+\hbar \hat{L}_z\end{align}</script><p>代入得</p><script type="math/tex; mode=display">\hat{L}_{-} \hat{L}_{+} | ab_{\mathrm{max}} \rangle=(\hat{L}^2-\hat{L}_z^2-\hbar \hat{L}_z) | ab_{\mathrm{max}} \rangle=(a-b_{\mathrm{max}}^2-\hbar b_{\mathrm{max}}) | ab_{\mathrm{max}} \rangle=\boldsymbol{0} \\\hat{L}_{-} \hat{L}_{+} | ab_{\mathrm{min}} \rangle=(\hat{L}^2-\hat{L}_z^2+\hbar \hat{L}_z) | ab_{\mathrm{min}} \rangle=(a-b_{\mathrm{min}}^2+\hbar b_{\mathrm{min}}) | ab_{\mathrm{min}} \rangle=\boldsymbol{0}</script><p>比照方程两边可知$a=b_{\mathrm{max}}^2+\hbar b_{\mathrm{max}}=b_{\mathrm{min}}^2-\hbar b_{\mathrm{min}}$,移项得$(b_{\mathrm{max}}+b_{\mathrm{min}})(b_{\mathrm{max}}-b_{\mathrm{min}}+\hbar)=0$,对应的方程解为$b_{\mathrm{max}}=-b_{\mathrm{min}}$或$b_{\mathrm{max}}=b_{\mathrm{min}}-\hbar$,但由于$b_{\mathrm{max}}>b_{\mathrm{min}}>b_{\mathrm{min}}-\hbar$,故符合条件的唯一解为$b_{\mathrm{max}}=-b_{\mathrm{min}}$。</p><p>之后,我们回想起上升/下降算符的作用效果:使态矢对于$\hat{L}_{z}$的本征值$b$增加/减少一个$\hbar$,因此$b_{\mathrm{max}}-b_{\mathrm{min}}$必然为整数,从而设$j$为整数或半整数,则$b_{\mathrm{max}}-b_{\mathrm{min}}=2j \hbar$,结合$b_{\mathrm{max}}=-b_{\mathrm{min}}$,便得$b_{\mathrm{max}}=j \hbar$与$b_{\mathrm{min}}=-j \hbar$(此时$b=m \hbar; m=-j,-(j-1),\dots,j-1,j$),代回本征值$a$的表达式,则$a=(j \hbar)^2+\hbar \cdot j \hbar=j(j+1) \hbar^2$。</p><p>到这里,我们得到了两个本征值的表达式,剩下尚未求出的参数,是$\hat{L}_{\pm} | ab \rangle=c_{\pm} | a,b \pm \hbar \rangle$中$c_{\pm}$的大小,而这一部分的推导过程较为简单:</p><script type="math/tex; mode=display">\begin{align}&\quad \hat{L}_{\pm} | ab \rangle=c_{\pm} | a,b \pm \hbar \rangle \\ &\Rightarrow \langle ab | \hat{L}_{\pm}^{\dagger}=\langle ab | (\hat{L}_x \pm \mathrm{i} \hat{L}_y)^{\dagger}=\langle ab | (\hat{L}_x \mp \mathrm{i} \hat{L}_y)=\langle ab | \hat{L}_{\mp}=\langle a,b \pm \hbar | c_{\pm}^{*} \\ &\Rightarrow \langle ab | \hat{L}_{\mp} \hat{L}_{\pm} | ab \rangle=\langle a,b \pm \hbar | c_{\pm}^{*} \cdot c_{\pm} | a,b \pm \hbar \rangle=\big| c_{\pm} \big|^2 \\ &\Rightarrow \langle ab | (\hat{L}^2-\hat{L}_z^2 \mp \hbar \hat{L}_z) | ab \rangle=a-b^2 \mp \hbar b=\big[ j(j+1)-m(m \pm 1) \big] \hbar^2=\big| c_{\pm} \big|^2 \\ &\quad (\mathrm{Suppose \; | ab \rangle \; and \; | a,b \pm \hbar \rangle \; have \; been \; normalized.})\end{align}</script><p>若$c_{\pm}$取为实数,则$c_{\pm}=\sqrt{j(j+1)-m(m \pm 1)} \hbar$。最终,角动量算符的本征态与本征值如下(为表述方便,我们将本征矢量$| ab \rangle$改写为$| jm \rangle$):</p><script type="math/tex; mode=display">\hat{L}^2 | jm \rangle=j(j+1) \hbar^2 | jm \rangle \quad \hat{L}_z | jm \rangle=m \hbar | jm \rangle \quad \hat{L}_{\pm} | jm \rangle=\sqrt{j(j+1)-m(m \pm 1)} \hbar | j,m \pm 1 \rangle</script><h4 id="I-7-角动量算符的球坐标表示"><a href="#I-7-角动量算符的球坐标表示" class="headerlink" title="[I-7] 角动量算符的球坐标表示(*)"></a>[I-7] 角动量算符的球坐标表示(*)</h4><p>[I-5]与[I-6]节采用的是角动量算符在直角坐标下的表现形式,这种形式在描述原子或分子轨道的状态时较为不便。为此,我们可以利用原子或高对称性分子轨道的球对称性,将角动量算符改用球坐标描述。</p><p>首先,我们给出两种坐标的转换公式,以及相应的全微分公式</p><script type="math/tex; mode=display">\begin{align}\begin{cases} x=r \sin{\theta} \cos{\varphi} \\ y=r \sin{\theta} \sin{\varphi} \\ z=r \cos{\theta} \end{cases} \; &\Rightarrow \; \begin{cases} dx=\sin{\theta} \cos{\varphi} \; dr+r \cos{\theta} \cos{\varphi} \; d \theta-r \sin{\theta} \sin{\varphi} \; d \varphi \\ dy=\sin{\theta} \sin{\varphi} \; dr+r \cos{\theta} \sin{\varphi} \; d \theta+r \sin{\theta} \cos{\varphi} \; d \varphi \\ dz=\cos{\theta} \; dr-r \sin{\theta} \; d \theta \end{cases} \\\begin{cases} r=\sqrt{x^2+y^2+z^2} \\ \theta=\arctan{\frac{\sqrt{x^2+y^2}}{z}} \\ \varphi=\arctan{\frac{y}{x}} \end{cases} \; &\Rightarrow \; \begin{cases} dr=\frac{x dx+y dy+zdz}{\sqrt{x^2+y^2+z^2}}=\sin{\theta} \cos{\varphi} \;dx+\sin{\theta} \sin{\varphi} \; dy+\cos{\theta} \; dz \\ d \theta=\frac{xz dx+yz dy-(x^2+y^2) dz}{(x^2+y^2+z^2) \sqrt{x^2+y^2}}=\frac{\cos{\theta} \cos{\varphi}}{r} \; dx+\frac{\cos{\theta} \sin{\varphi}}{r} \; dy-\frac{\sin{\theta}}{r} \; dz \\ d \varphi=\frac{-y dx+x dy}{x^2+y^2}=-\frac{\sin{\varphi}}{r \sin{\theta}} \; dx+\frac{\cos{\varphi}}{r \sin{\theta}} \; dy \end{cases}\end{align}</script><p>上述坐标表示方式对应于下图</p><p><img src="/2022/11/17/NMR-spectroscopy-under-the-perspective-of-quantum-mechanics-I/spherical-coordinates.png" alt="图1 本文采用的球坐标表示方式"></p><p>代入角动量算符在直角坐标系下的表达式,我们有</p><script type="math/tex; mode=display">\begin{align}\hat{L}_x &= -\mathrm{i} \hbar (\hat{y} \frac{\partial}{\partial z}-\hat{z} \frac{\partial}{\partial y}) \\&= -\mathrm{i} \hbar \Big[ \hat{y} (\frac{\partial r}{\partial z} \frac{\partial}{\partial r}+\frac{\partial \theta}{\partial z} \frac{\partial}{\partial \theta}+\frac{\partial \varphi}{\partial z} \frac{\partial}{\partial \varphi})-\hat{z} (\frac{\partial r}{\partial y} \frac{\partial}{\partial r}+\frac{\partial \theta}{\partial y} \frac{\partial}{\partial \theta}+\frac{\partial \varphi}{\partial y} \frac{\partial}{\partial \varphi}) \Big] \\&= -\mathrm{i} \hbar \Big[ r \sin{\theta} \sin{\varphi} (\cos{\theta} \frac{\partial}{\partial r}-\frac{\sin{\theta}}{r} \frac{\partial}{\partial \theta}) \\ &\quad \quad -r \cos{\theta} (\sin{\theta} \sin{\varphi} \frac{\partial}{\partial r}+\frac{\cos{\theta} \sin{\varphi}}{r} \frac{\partial}{\partial \theta}+\frac{\cos{\varphi}}{r \sin{\theta}} \frac{\partial}{\partial \varphi}) \Big] \\&= \mathrm{i} \hbar (\sin{\varphi} \frac{\partial}{\partial \theta}+\cot{\theta} \cos{\varphi} \frac{\partial}{\partial \varphi}) \\\hat{L}_y &= -\mathrm{i} \hbar (\hat{z} \frac{\partial}{\partial x}-\hat{x} \frac{\partial}{\partial z}) \\&= -\mathrm{i} \hbar \Big[ \hat{z} (\frac{\partial r}{\partial x} \frac{\partial}{\partial r}+\frac{\partial \theta}{\partial x} \frac{\partial}{\partial \theta}+\frac{\partial \varphi}{\partial x} \frac{\partial}{\partial \varphi})-\hat{x} (\frac{\partial r}{\partial z} \frac{\partial}{\partial r}+\frac{\partial \theta}{\partial z} \frac{\partial}{\partial \theta}+\frac{\partial \varphi}{\partial z} \frac{\partial}{\partial \varphi}) \Big] \\&= -\mathrm{i} \hbar \Big[ r \cos{\theta} (\sin{\theta} \cos{\varphi} \frac{\partial}{\partial r}+\frac{\cos{\theta} \cos{\varphi}}{r} \frac{\partial}{\partial \theta}-\frac{\sin{\varphi}}{r \sin{\theta}} \frac{\partial}{\partial \varphi}) \\ &\quad \quad-r \sin{\theta} \cos{\varphi} (\cos{\theta} \frac{\partial}{\partial r}-\frac{\sin{\theta}}{r} \frac{\partial}{\partial \theta}) \Big] \\&= \mathrm{i} \hbar (-\cos{\varphi} \frac{\partial}{\partial \theta}+\cot{\theta} \sin{\varphi} \frac{\partial}{\partial \varphi}) \\\hat{L}_z &= -\mathrm{i} \hbar (\hat{x} \frac{\partial}{\partial y}-\hat{y} \frac{\partial}{\partial x}) \\&= -\mathrm{i} \hbar \Big[ \hat{x} (\frac{\partial r}{\partial y} \frac{\partial}{\partial r}+\frac{\partial \theta}{\partial y} \frac{\partial}{\partial \theta}+\frac{\partial \varphi}{\partial y} \frac{\partial}{\partial \varphi})-\hat{y} (\frac{\partial r}{\partial x} \frac{\partial}{\partial r}+\frac{\partial \theta}{\partial x} \frac{\partial}{\partial \theta}+\frac{\partial \varphi}{\partial x} \frac{\partial}{\partial \varphi}) \Big] \\&= -\mathrm{i} \hbar \Big[ r \sin{\theta} \cos{\varphi} (\sin{\theta} \sin{\varphi} \frac{\partial}{\partial r}+\frac{\cos{\theta} \sin{\varphi}}{r} \frac{\partial}{\partial \theta}+\frac{\cos{\varphi}}{r \sin{\theta}} \frac{\partial}{\partial \varphi}) \\ &\quad \quad -r \sin{\theta} \sin{\varphi} (\sin{\theta} \cos{\varphi} \frac{\partial}{\partial r}+\frac{\cos{\theta} \cos{\varphi}}{r} \frac{\partial}{\partial \theta}-\frac{\sin{\varphi}}{r \sin{\theta}} \frac{\partial}{\partial \varphi}) \Big] \\&= -\mathrm{i} \hbar \frac{\partial}{\partial \varphi} \\\end{align}</script><p>进而推知</p><script type="math/tex; mode=display">\begin{align}\hat{L}_{\pm} &= \hat{L}_x \pm \mathrm{i} \hat{L}_y=\mathrm{i} \hbar \Big[ (\sin{\varphi} \mp \mathrm{i} \cos{\varphi}) \frac{\partial}{\partial \theta}+(\cos{\varphi} \pm \mathrm{i} \sin{\varphi}) \cot{\theta} \frac{\partial}{\partial \varphi} \Big] \\ &= \mathrm{i} \hbar \Big[ \mp \mathrm{i} \mathrm{e}^{\pm \mathrm{i} \varphi} \frac{\partial}{\partial \theta}+\mathrm{e}^{\pm \mathrm{i} \varphi} \cot{\theta} \frac{\partial}{\partial \varphi} \Big]=\mathrm{e}^{\pm \mathrm{i} \varphi} \hbar (\pm \frac{\partial}{\partial \theta}+\mathrm{i} \cot{\theta} \frac{\partial}{\partial \varphi}) \\\hat{L}^2 &=\hat{L}_z^2+\hbar \hat{L}_z+\hat{L}_{-} \hat{L}_{+} \\ &= -\hbar^2 \frac{\partial^2}{\partial \varphi^2}-\mathrm{i} \hbar^2 \frac{\partial}{\partial \varphi}+\mathrm{e}^{-\mathrm{i} \varphi} \hbar (-\frac{\partial}{\partial \theta}+\mathrm{i} \cot{\theta} \frac{\partial}{\partial \varphi}) \cdot \mathrm{e}^{\mathrm{i} \varphi} \hbar (\frac{\partial}{\partial \theta}+\mathrm{i} \cot{\theta} \frac{\partial}{\partial \varphi}) \\ &= -\hbar^2 \frac{\partial^2}{\partial \varphi^2}-\mathrm{i} \hbar^2 \frac{\partial}{\partial \varphi}+\hbar^2 (-\frac{\partial^2}{\partial \theta^2}+\frac{\mathrm{i}}{\sin^2{\theta}} \frac{\partial}{\partial \varphi}-\mathrm{i} \cot{\theta} \frac{\partial^2}{\partial \theta \; \partial \varphi}) \\ &\quad \quad -\hbar^2 \cot{\theta} (\frac{\partial}{\partial \theta}+\mathrm{i} \cot{\theta} \frac{\partial}{\partial \varphi})+\mathrm{i} \hbar^2 \cot{\theta} (\frac{\partial^2}{\partial \varphi \; \partial \theta}+\mathrm{i} \cot{\theta} \frac{\partial^2}{\partial \varphi^2}) \\ &= -\hbar^2 (\frac{1}{\sin^2{\theta}} \frac{\partial^2}{\partial \varphi^2}+\frac{\partial^2}{\partial \theta^2}+\cot{\theta} \frac{\partial}{\partial \theta}) \quad (\mathrm{Since} \; \frac{\partial^2}{\partial \theta \; \partial \varphi}=\frac{\partial^2}{\partial \varphi \; \partial \theta}.) \\ &= -\hbar^2 \Big[ \frac{1}{\sin^2{\theta}} \frac{\partial^2}{\partial \varphi^2}+\frac{1}{\sin{\theta}} (\sin{\theta} \frac{\partial}{\partial \theta}) \frac{\partial}{\partial \theta}+\frac{1}{\sin{\theta}} \frac{\partial (\sin{\theta})}{\partial \theta} \frac{\partial}{\partial \theta} \Big] \\ &= -\hbar^2 \Big[ \frac{1}{\sin^2{\theta}} \frac{\partial^2}{\partial \varphi^2}+\frac{1}{\sin{\theta}} \frac{\partial}{\partial \theta} (\sin{\theta} \frac{\partial}{\partial \theta}) \Big]\end{align}</script><h4 id="I-8-角动量算符的应用——球坐标下定态薛定谔方程的求解"><a href="#I-8-角动量算符的应用——球坐标下定态薛定谔方程的求解" class="headerlink" title="[I-8] 角动量算符的应用——球坐标下定态薛定谔方程的求解(*)"></a>[I-8] 角动量算符的应用——球坐标下定态薛定谔方程的求解(*)</h4><p>现在,让我们采用[I-7]节的结论,求解球坐标下的定态薛定谔方程。首先,我们引入广义坐标系下梯度的表达式,</p><script type="math/tex; mode=display">(q_1,q_2,\dots,q_n) \rightarrow (u_1,u_2,\dots,u_n) \\ \nabla \phi=\sum\limits_{i=1}^{n} \frac{1}{h_i} \frac{\partial \phi}{\partial u_i} \boldsymbol{e}_i \quad \nabla^2 \phi=\frac{1}{\prod\limits_{j=1}^{n} h_j} \frac{\partial}{\partial u_i} \Big( \frac{\prod\limits_{j=1}^{n} h_j}{h_i^2} \frac{\partial}{\partial u_i} \Big) \quad h_i=\sqrt{\sum\limits_{j=1}^{n} \Big( \frac{\partial q_j}{\partial u_i} \Big)^2}</script><p>并用此法快速写出球坐标下梯度和拉普拉斯算符的表达式:</p><script type="math/tex; mode=display">\begin{align}h_r &= \sqrt{(\sin{\theta} \cos{\varphi})^2+(\sin{\theta} \sin{\varphi})^2+(\cos{\theta})^2}=1 \\h_{\theta} &= \sqrt{(r \cos{\theta} \cos{\varphi})^2+(r \cos{\theta} \sin{\varphi})^2+(-r \sin{\theta})^2}=r \\h_{\varphi} &= \sqrt{(-r \sin{\theta} \sin{\varphi})^2+(r \sin{\theta} \cos{\varphi})^2+0^2}=r \sin{\theta} \\\nabla &= \frac{1}{h_r} \frac{\partial}{\partial r} \boldsymbol{e}_r+\frac{1}{h_{\theta}} \frac{\partial}{\partial \theta} \boldsymbol{e}_{\theta}+\frac{1}{h_{\varphi}} \frac{\partial}{\partial \varphi} \boldsymbol{e}_{\varphi} \\ &= \frac{\partial}{\partial r} \boldsymbol{e}_r+\frac{1}{r} \frac{\partial}{\partial \theta} \boldsymbol{e}_{\theta}+\frac{1}{r \sin{\theta}} \frac{\partial}{\partial \varphi} \boldsymbol{e}_{\varphi} \\\nabla^2 &= \frac{1}{h_r h_{\theta} h_{\varphi}} \Big[ \frac{\partial}{\partial r} (\frac{h_{\theta} h_{\varphi}}{h_r} \frac{\partial}{\partial r})+\frac{\partial}{\partial \theta} (\frac{h_{r} h_{\varphi}}{h_{\theta}} \frac{\partial}{\partial \theta})+\frac{\partial}{\partial \varphi} (\frac{h_r h_{\theta}}{h_{\varphi}} \frac{\partial}{\partial \varphi}) \Big] \\ &= \frac{1}{1 \cdot r \cdot r \sin{\theta}} \Big[ \frac{\partial}{\partial r} (\frac{r \cdot r \sin{\theta}}{1} \frac{\partial}{\partial r})+\frac{\partial}{\partial \theta} (\frac{1 \cdot r \sin{\theta}}{r} \frac{\partial}{\partial \theta})+\frac{\partial}{\partial \varphi} (\frac{1 \cdot r}{r \sin{\theta}} \frac{\partial}{\partial \varphi}) \Big] \\ &= \frac{1}{r^2 \sin{\theta}} \Big[ 2r \sin{\theta} \frac{\partial}{\partial r}+r^2 \sin{\theta} \frac{\partial^2}{\partial r^2}+\cos{\theta} \frac{\partial}{\partial \theta}+\sin{\theta} \frac{\partial^2}{\partial \theta^2}+\frac{1}{\sin{\theta}} \frac{\partial^2}{\partial \varphi^2} \Big] \\ &= \frac{1}{r^2} \Big[ \frac{\partial}{\partial r} (r^2 \frac{\partial}{\partial r})+\frac{1}{\sin{\theta}} \frac{\partial}{\partial \theta} (\sin{\theta} \frac{\partial}{\partial \theta})+\frac{1}{\sin^2{\theta}} \frac{\partial^2}{\partial \varphi^2} \Big]\end{align}</script><p>接下来,我们就可以将定态薛定谔方程$\hat{H} \Psi=(-\frac{\hbar^2}{2m} \nabla^2+V) \Psi=E \Psi$用球坐标表示:</p><script type="math/tex; mode=display">\begin{align}&\quad -\frac{\hbar^2}{2m} \frac{1}{r^2} \Big[ \frac{\partial}{\partial r} (r^2 \frac{\partial}{\partial r})+\frac{1}{\sin{\theta}} \frac{\partial}{\partial \theta} (\sin{\theta} \frac{\partial}{\partial \theta})+\frac{1}{\sin^2{\theta}} \frac{\partial^2}{\partial \varphi^2} \Big] \Psi(r,\theta,\varphi)+V(r,\theta,\varphi) \Psi(r,\theta,\varphi) \\&= -\frac{\hbar^2}{2m} \frac{1}{r^2} \Big[ \frac{\partial}{\partial r} (r^2 \frac{\partial}{\partial r})-\frac{\hat{L}^2}{\hbar^2} \Big] \Psi(r,\theta,\varphi)+V(r,\theta,\varphi) \Psi (r,\theta,\varphi)=E \Psi(r,\theta,\varphi)\end{align}</script><p>上式将径向部分与角度部分的算符拆分,其中角度部分恰好可以用角动量平方算符描述。为进一步求解该方程,我们假定波函数的径向部分与角度部分可分离,即$\Psi(r,\theta,\varphi)=R(r) Y(\theta,\varphi)$,此时代入上式得</p><script type="math/tex; mode=display">-\frac{\hbar^2}{2m} Y(\theta,\varphi) \cdot \frac{1}{r^2} \frac{\partial}{\partial r} \Big[ r^2 \frac{\partial R(r)}{\partial r} \Big]+\frac{R(r)}{2mr^2} \hat{L}^2 Y(\theta,\varphi)+V(r,\theta,\varphi) R(r) Y(\theta,\varphi)=E R(r) Y(\theta,\varphi)</script><p>两边除以$R(r) Y(\theta,\varphi)$,得</p><script type="math/tex; mode=display">-\frac{\hbar^2}{2m} \frac{1}{R(r)} \cdot \frac{1}{r^2} \frac{\partial}{\partial r} \Big[ r^2 \frac{\partial R(r)}{\partial r} \Big]+\frac{1}{2mr^2 \cdot Y(\theta,\varphi)} \hat{L}^2 Y(\theta,\varphi)+V(r,\theta,\varphi)=E</script><p>由于一般情况下,势能仅是原点距离的函数,$V(r,\theta,\varphi)=V(r)$,因此移项后可变为</p><script type="math/tex; mode=display">\begin{align}&\quad -\frac{\hbar^2}{2m} \frac{1}{R(r)} \cdot \frac{1}{r^2} \frac{\partial}{\partial r} \Big[ r^2 \frac{\partial R(r)}{\partial r} \Big]+V(r)-E+\frac{1}{2mr^2 \cdot Y(\theta,\varphi)} \hat{L}^2 Y(\theta,\varphi)=0 \\&\Rightarrow \frac{1}{R(r)} \frac{\partial}{\partial r} \Big[ r^2 \frac{\partial R(r)}{\partial r} \Big]-\frac{2mr^2}{\hbar^2} \big[ V(r)-E \big]=\frac{1}{\hbar^2 Y(\theta,\varphi)} \hat{L}^2 Y(\theta,\varphi)=\lambda\end{align}</script><p>其中$\lambda$为常数,从而径向部分与角度部分的本征方程可分拆为</p><script type="math/tex; mode=display">\frac{\partial}{\partial r} \Big[ r^2 \frac{\partial R(r)}{\partial r} \Big]-\frac{2mr^2}{\hbar^2} \big[ V(r)-E \big] R(r)=\lambda R(r) \\ \hat{L}^2 Y(\theta,\varphi)=\lambda \hbar^2 Y(\theta,\varphi)</script><p>沿着这一思路,我们还可以将角度部分的两个变量进行进一步拆分。记$Y(\theta,\varphi)=\Theta(\theta) \Phi(\varphi)$,则由于$[\hat{L}^2,\hat{L}_z]=0$,即$\hat{L}^2$与$\hat{L}_z$具有共同的本征态,且$\hat{L}_z=-\mathrm{i} \hbar \frac{\partial}{\partial \varphi}$,不含与$\theta$相关的算符,因此</p><script type="math/tex; mode=display">\hat{L}_z Y(\theta,\varphi)=\hat{L}_z [\Theta(\theta) \Phi(\varphi)]=\Theta(\theta) \Big[ -\mathrm{i} \hbar \frac{\partial \Phi(\varphi)}{\partial \varphi} \Big]=\mu \Theta(\theta) \Phi(\varphi) \; \Rightarrow \; -\mathrm{i} \hbar \frac{\partial \Phi(\varphi)}{\partial \varphi}=\mu \Phi(\varphi)</script><p>上述方程的通解为$\Phi(\varphi)=\Phi(0) \mathrm{e}^{\frac{\mathrm{i} \mu}{\hbar} \varphi}$,考虑边界条件,有$\Phi(0)=\Phi(2 \pi) \neq 0 \Rightarrow \mathrm{e}^{\frac{2 \pi \mathrm{i} \mu}{\hbar}}=1$,进而$\frac{2 \pi \mathrm{i} \mu}{\hbar}=2m \pi \mathrm{i} \; (m=0,\pm 1,\pm 2,\dots)$,即$\hat{L}_z$对$\Phi(\varphi)$的本征值为$\mu=m \hbar \; (m=0,\pm 1,\pm 2,\dots)$,同时$\Phi(\varphi)=\Phi(0) \mathrm{e}^{\mathrm{i} m \varphi}$。</p><p>这样,角度部分的本征函数便改写为$Y(\theta,\varphi)=\Theta(\theta) \mathrm{e}^{\mathrm{i} m \varphi}$,我们将其代回角度部分的本征方程,并将角动量平方算符展开,得</p><script type="math/tex; mode=display">\begin{align}&\quad -\hbar^2 \Big[ \frac{1}{\sin^2{\theta}} \frac{\partial^2}{\partial \varphi^2}+\frac{1}{\sin{\theta}} \frac{\partial}{\partial \theta} (\sin{\theta} \frac{\partial}{\partial \theta}) \Big] \Theta(\theta) \mathrm{e}^{\mathrm{i} m \varphi}=\lambda \hbar^2 \Theta(\theta) \mathrm{e}^{\mathrm{i} m \varphi} \\ &\Rightarrow -\hbar^2 \Big\{ -\frac{m^2 \Theta(\theta)}{\sin^2{\theta}} \mathrm{e}^{\mathrm{i} m \varphi}+\frac{1}{\sin{\theta}} \frac{\partial}{\partial \theta} \big[ \sin{\theta} \frac{\partial \Theta(\theta)}{\partial \theta} \big] \cdot \mathrm{e}^{\mathrm{i} m \varphi} \Big\}=\lambda \hbar^2 \Theta(\theta) \mathrm{e}^{\mathrm{i} m \varphi} \\ &\Rightarrow \frac{1}{\sin{\theta}} \frac{\partial}{\partial \theta} \Big[ \sin{\theta} \frac{\partial \Theta(\theta)}{\partial \theta} \Big]+\Big[ \lambda -\frac{m^2}{\sin^2{\theta}} \Big] \Theta(\theta)=0\end{align}</script><p> y(x)=\Theta(\theta) \end{cases}$,则$dx=-\sin{\theta} d \theta \; (x \in [-1,1])$,$\frac{d}{d \theta}=\frac{dx}{d \theta} \frac{d}{dx}=-\sin{\theta} \frac{d}{dx}$,此时上述方程变为</p><script type="math/tex; mode=display">\begin{align}&\quad \frac{1}{\sin{\theta}} \cdot (-\sin{\theta}) \frac{d}{dx} \Big[ \sin{\theta} \cdot (-\sin{\theta} \frac{dy}{dx}) \Big]+\Big[ \lambda -\frac{m^2}{1-x^2} \Big] y(x)=0 \\ &\Rightarrow \frac{d}{dx} \Big[ (1-x^2) \frac{dy}{dx} \Big]+\Big[ \lambda -\frac{m^2}{1-x^2} \Big] y=0 \\ &\Rightarrow (1-x^2) \frac{d^2 y}{dx^2}-2x \frac{dy}{dx}+\Big[ \lambda -\frac{m^2}{1-x^2} \Big] y=0\end{align}</script><p>当$m=0$时,原式即为勒让德方程$(1-x^2) \frac{d^2 y}{dx^2}-2x \frac{dy}{dx}+\lambda y=0$,对$y(x)$作级数展开$y=\sum\limits_{i=0}^{\infty} c_i x^i$,则$\frac{dy}{dx}=\sum\limits_{i=1}^{\infty} i c_i x^{i-1}$,$\frac{d^2 y}{dx^2}=\sum\limits_{i=2}^{\infty} i(i-1) c_i x^{i-2}$,代入勒让德方程,有</p><script type="math/tex; mode=display">\begin{align}&\quad (1-x^2) \sum\limits_{i=2}^{\infty} i(i-1) c_i x^{i-2}-2x \sum\limits_{i=1}^{\infty} i c_i x^{i-1}+\lambda \sum\limits_{i=0}^{\infty} c_i x^i=0 \\ &\Rightarrow \sum\limits_{i=0}^{\infty} (i+2)(i+1) c_{i+2} x^i-\sum\limits_{i=0}^{\infty} i(i-1) c_i x^i-\sum\limits_{i=0}^{\infty} 2i c_i x^i+\sum\limits_{i=0}^{\infty} \lambda c_i x^i=0 \\ &\Rightarrow \sum\limits_{i=0}^{\infty} \big\{ (i+2)(i+1) c_{i+2}-\big[ i(i+1)-\lambda \big] c_i \big\} x^i=0\end{align}</script><p>该方程对$x \in [-1,1]$均成立,因此唯一符合要求的系数解为$c_{i+2}=\frac{i(i+1)-\lambda}{(i+2)(i+1)} c_i$,对应的线性无关的解$y(x)$为:</p><script type="math/tex; mode=display">c_0 \neq 0,c_1=0 \quad y(x)=\sum\limits_{i=0}^{\infty} c_{2i} x^{2i} \\ c_0=0,c_1 \neq 0 \quad y(x)=\sum\limits_{i=0}^{\infty} c_{2i+1} x^{2i+1}</script><p>考虑到波函数在其定义域内必然收敛于一定值,而$x=1$时,若所有系数均不为零(即$y(x)$为无穷级数),可证明$y(x)$必然发散,矛盾!因此$y(x)$只能为截断的多项式,即在某个有限的整数$l$处,有$\frac{i(i+1)-\lambda}{(i+2)(i+1)} \Big|_{i=l}=0$,故$\lambda=l(l+1) \; (l=0,1,2,\dots)$为离散值,从而$\hat{L}^2$的本征值$l(l+1) \hbar^2$亦为离散值。</p><p>下一步是求出勒让德多项式$y(x)$(换言之,$\Theta(\theta)$)的系数,显然$c_{i+2}=\frac{i(i+1)-l(l+1)}{(i+2)(i+1)} c_i=-\frac{(l-i)(l+i+1)}{(i+2)(i+1)} c_i$,若$l$为偶数,则非零项必为偶数项,故迭代可得:</p><script type="math/tex; mode=display">\begin{align}c_{2i} &= -\frac{(l-2i+2)(l+2i-1)}{2i(2i-1)} c_{2i-2} \\&= \Big[ -\frac{(l-2i+2)(l+2i-1)}{2i(2i-1)} \Big] \cdot \Big[ -\frac{(l-2i+4)(l+2i-3)}{(2i-2)(2i-3)} \Big] c_{2i-4} \\&= \dots =(-1)^{i} \frac{\frac{l!!}{(l-2i)!!} \frac{(l+2i-1)!!}{(l-1)!!}}{(2i)!} c_0=(-1)^{i} \frac{(\frac{l}{2})! 2^{\frac{l}{2}} \cdot (l+2i-1)!! \cdot (l+2i)!! \cdot l!!}{(2i)! \cdot (\frac{l}{2}-i)! 2^{\frac{l}{2}-i} \cdot (l-1)!! \cdot l!! \cdot (l+2i)!!} c_0 \\&= (-1)^{i} \frac{(\frac{l}{2})! 2^{\frac{l}{2}} \cdot (l+2i)! \cdot (\frac{l}{2})! 2^{\frac{l}{2}}}{(2i)! \cdot (\frac{l}{2}-i)! 2^{\frac{l}{2}-i} \cdot l! \cdot (\frac{l}{2}+i)! 2^{\frac{l}{2}+i}} c_0=(-1)^{i} \frac{(l+2i)! \big[ (\frac{l}{2})! \big]^2}{(2i)! l! (\frac{l}{2}-i)! (\frac{l}{2}+i)!} c_0\end{align}</script><p>从多项式导数的角度而言,因$\frac{d^p}{dx^p} x^{u}=\frac{u!}{(u-p)!} x^{u-p} \; (u \geq p)$,故令$2i=u-p$,$p=l$,则$\frac{d^l}{dx^l} x^{2i+l}=\frac{(2i+l)!}{(2i)!} x^{2i} \; (2i \geq 0)$,右式系数即$c_{2i}$递推式的一部分。若构造$f(x)=\frac{1}{2^{l} l!} (x^2-1)^l$,其展开后为$f(x)=\frac{1}{2^{l} l!} \sum\limits_{i=0}^{l} C_{l}^{i} (x^2)^{i} (-1)^{l-i}=\frac{1}{2^{l} l!} \sum\limits_{k=0}^{l} C_{l}^{k} (x^2)^{l-k} (-1)^{k}$,相应的$l$阶导数为</p><script type="math/tex; mode=display">\begin{align}\frac{d^l f}{dx^l} &= \frac{1}{2^{l} l!} \sum\limits_{i=\frac{l}{2}}^{l} C_{l}^{i} (-1)^{l-i} \frac{d^l}{dx^l} x^{l+2i}=\frac{1}{2^{l} l!} \sum\limits_{i=0}^{\frac{l}{2}} \frac{(-1)^{\frac{l}{2}-i} l!}{(\frac{l}{2}+i)! (\frac{l}{2}-i)!} \frac{(2i+l)!}{(2i)!} x^{2i} \\ &= \frac{(-1)^{\frac{l}{2}} l!}{2^l \big[ (\frac{l}{2})! \big]^2} \sum\limits_{i=0}^{\frac{l}{2}} (-1)^{i} \frac{(l+2i)! \big[ (\frac{l}{2})! \big]^2}{(2i)! l! (\frac{l}{2}-i)! (\frac{l}{2}+i)!} x^{2i} \quad (\mathrm{since} \; (-1)^i=(-1)^{-i})\end{align}</script><p>令$c_0=\frac{(-1)^{\frac{l}{2}} l!}{2^l \big[ (\frac{l}{2})! \big]^2}$,则$f(x)$的$l$阶导数即为$y(x)$的系数,由此推出勒让德方程的表达式为$P_l(x)=y(x)=\frac{1}{2^l l!} \frac{d^l}{dx^l} (x^2-1)^{l}$。以上推导过程对$l$为奇数的情形亦适用,此处不再赘述。</p><p>当$m \neq 0$时,因$x=\pm 1$处为奇点,故须考虑奇点处的渐近方程表示。令$x’=1-x$,则$dx’=-dx$,且$x’ \rightarrow 0$时,$\lambda$相对于$-\frac{m^2}{1-x^2}$可忽略,原微分方程变为</p><script type="math/tex; mode=display">\begin{align}&\quad x'(2-x') \frac{d^2 y}{dx'^2}+2(1-x') \frac{dy}{dx'}-\frac{m^2}{x'(2-x')} y=0 \\&\Rightarrow \frac{d^2 y}{dx'^2}+\frac{2(1-x')}{x'(2-x')} \frac{dy}{dx'}-\frac{m^2}{x'^2(2-x')^2} y=0 \\&\Rightarrow \frac{d^2 y}{dx'^2}+\frac{1}{x'} \frac{dy}{dx'}-\frac{m^2}{4x'^2} y=0 \quad (\mathrm{when} \; x' \rightarrow 0) \\\end{align}</script><p>令$y=(x’)^s$,则微分方程可化为</p><script type="math/tex; mode=display">s(s-1)(x')^{s-2}+\frac{1}{x'} \cdot s(x')^{s-1}-\frac{m^2}{4} (x')^{s-2}=(x')^{s-2} \big[ s(s-1)+s-\frac{m^2}{4} \big]=0</script><p>解得$s=\pm \frac{|m|}{2}$,但若取$s=-\frac{|m|}{2}$,则$y=(x’)^s$在$x’=0$处发散,因此合理的解只能是$s=\frac{|m|}{2}$,从而$x=1$处的渐近方程为$y=(x’)^{\frac{|m|}{2}}=(1-x)^{\frac{|m|}{2}}$。同理可得,$x=-1$处的渐近方程为$y=(1+x)^{\frac{|m|}{2}}$。综合两个奇点处的渐近方程表示,我们可以写出原微分方程的通解$y=(1-x)^{\frac{|m|}{2}} (1+x)^{\frac{|m|}{2}} u(x)=(1-x^2)^{\frac{|m|}{2}} u(x)$,其中$u(x)$为一级数(可能为无穷级数,也可能为有穷的多项式),对其求导得</p><script type="math/tex; mode=display">\begin{align}\frac{dy}{dx} &= \frac{|m|}{2} (1-x^2)^{\frac{|m|}{2}-1} \cdot (-2x) u(x)+(1-x^2)^{\frac{|m|}{2}} \frac{du}{dx} \\ &= -(1-x^2)^{\frac{|m|}{2}} (\frac{|m|xu}{1-x^2}-\frac{du}{dx}) \\\frac{d^2 y}{dx^2} &= -\frac{|m|}{2} (1-x^2)^{\frac{|m|}{2}-1} \cdot (-2x) \cdot (\frac{|m|xu}{1-x^2}-\frac{du}{dx}) \\ &\quad \quad -(1-x^2)^{\frac{|m|}{2}} \Big[ \frac{|m| (1+x^2) u}{(1-x^2)^2}+\frac{|m|x}{1-x^2} \frac{du}{dx}-\frac{d^2 u}{dx^2} \Big] \\ &= (1-x^2)^{\frac{|m|}{2}} \Big[ \frac{m^2 x^2 u}{(1-x^2)^2}-\frac{|m|(1+x^2)u}{(1-x^2)^2}-\frac{2|m|x}{1-x^2} \frac{du}{dx}+\frac{d^2 u}{dx^2} \Big]\end{align}</script><p>从而原微分方程可变换为</p><script type="math/tex; mode=display">(1-x^2) \frac{d^2 u}{dx^2}-2(|m|+1)x \frac{du}{dx}+[\lambda-|m|(|m|+1)] u=0</script><p>两边连续求导得</p><script type="math/tex; mode=display">(1-x^2) \frac{d^3 u}{dx^3}-2(|m|+2)x \frac{d^2 u}{dx^2}+\big[ \lambda-(|m|+1)(|m|+2) \big] \frac{du}{dx}=0 \\(1-x^2) \frac{d^4 u}{dx^4}-2(|m|+3)x \frac{d^3 u}{dx^3}+\big[ \lambda-(|m|+2)(|m|+3) \big] \frac{d^2 u}{dx^2}=0 \\\dots \dots</script><p>现在将上述方程与$m \neq 0$时的连带勒让德方程对比,我们发现,$u(x)$, $\frac{du}{dx}$, $\frac{d^2 u}{dx^2}$, $\dots$分别对应于$|m|$, $|m|+1$, $|m|+2$, $\dots$时的连带勒让德方程的通解。特别的,当$|m|=0$时,连带勒让德方程即退化为勒让德方程。因此,根据前述的连带勒让德方程的递推关系,我们有$u(x)=\frac{d^{|m|}}{dx^{|m|}} P_l(x)=\frac{1}{2^l l!} \frac{d^{|m|+l}}{dx^{|m|+l}} (x^2-1)^l$,从而连带勒让德方程的通解(记为$P_l^m(x)$)为</p><script type="math/tex; mode=display">P_l^m(x)=y(x)=(1-x^2)^{\frac{|m|}{2}} \frac{1}{2^l l!} \frac{d^{|m|+l}}{dx^{|m|+l}} (x^2-1)^l</script><p>至于$m \neq 0$时方程的本征值,由于此时的通解由$m=0$时的通解经多次求导而得,因此收敛条件与$m=0$相同,即$\hat{L}^2$的本征值为$\lambda \hbar^2=l(l+1) \hbar^2 \; (l=0,1,2,\dots)$;同时,当$|m|>l$时,$P_l^m(x)=0$,与波函数不为零矛盾,从而为保证波函数存在,$|m| \leq l$,即$\hat{L}_z$的本征值为$\mu=m \hbar \; (m=-l, -l+1, \dots, l-1, l)$。</p><p>经过以上复杂的推导后,我们最终得到$\hat{L}^2$与$\hat{L}_z$共同的本征函数$Y(\theta,\varphi)$的表达式(见下),现在只需要将其归一化,即可得到球谐函数$Y_{lm} (\theta,\varphi)$的表达式</p><script type="math/tex; mode=display">\begin{align}&\quad \begin{cases} Y(\theta, \varphi)=P_l^{\pm|m|}(\cos{\theta}) \mathrm{e}^{\mathrm{i} m \varphi} \\ Y_{lm}(\theta, \varphi)=c_Y Y(\theta, \varphi) \\ \iint |Y_{lm}(\theta, \varphi)|^2 \sin{\theta} d \theta d \varphi=1 \end{cases} \\ &\Rightarrow Y_{lm}(\theta, \varphi)=(-1)^{m} \sqrt{\frac{(l-m)!}{(l+m)!} \frac{2l+1}{4 \pi}} P_l^{m}(\cos{\theta}) \mathrm{e}^{\mathrm{i} m \varphi} \quad (m \in [-l,l])\end{align}</script><h4 id="I-9-量子力学体系随时间的变化——时间演化算符和哈密尔顿算符"><a href="#I-9-量子力学体系随时间的变化——时间演化算符和哈密尔顿算符" class="headerlink" title="[I-9] 量子力学体系随时间的变化——时间演化算符和哈密尔顿算符"></a>[I-9] 量子力学体系随时间的变化——时间演化算符和哈密尔顿算符</h4><p>量子力学不但是(也不能仅仅是)“静”的物理理论,也是“动”的物理理论,这是由于许多物理现象不但与某时刻的状态有关,还与该时刻之前的状态有关,而从该时刻前的状态变化到该时刻的状态,便会涉及量子力学体系随时间的变化,这便是最后一部分的内容。</p><p>不过,在开始这一部分的介绍之前,我们不得不接受这样一个事实——在量子力学中,时间(更准确地说,时刻)不再被认为是物理上的可观测量,而是一个参变量,这意味着时间无法用一个厄米算符表示。不过,从某一时刻的态矢$| u(t_0) \rangle$,经一段时间后转变为另一时刻的态矢$| u(t) \rangle$,这一过程可以用厄米算符$\hat{U}(t,t_0)$(称为时间演化算符)表示,且这一过程涉及到时间(更准确地说,时刻$t_0$以及$t$的变化$\Delta t=t-t_0$)。仿照[I-3]节中位移算符的性质,我们同样可以写出$\hat{U}(t,t_0)$的性质:</p><blockquote><p>i. $\hat{U}(t,t_0)$不影响态矢的内积,即对$| u(t) \rangle=\hat{U}(t,t_0) | u(t_0) \rangle$, $| v(t) \rangle=\hat{U}(t,t_0) | v(t_0) \rangle$,其内积满足$\langle v(t) | u(t) \rangle=\langle v(t_0) | \hat{U}^{\dagger}(t,t_0) \hat{U}(t,t_0) | u(t_0) \rangle=\langle v(t_0) | u(t_0) \rangle$;<br>ii. (<strong>时间演化的叠加</strong>)相继两段时间的演化等效于一段总时间的演化,即$\hat{U}(t_2,t_1)\hat{U}(t_1,t_0)=\hat{U}(t_2,t_0)$;<br>iii. 当$\Delta t=t-t_0 \rightarrow 0$时,$\hat{U}(t,t_0)$趋近于$\hat{I}$</p></blockquote><p>两相对比便会发现,时间演化算符的运算性质与位移算符差别不大,唯一的区别在于,时间演化算符不具有逆运算,这与现实世界中“时间无法倒流”的现象对应(当然,如果有一天确实观测到真正意义上的时间倒流,或许时间演化算符也会有良定义……吧)。因此,时间演化算符也具有类似于位移算符的表达形式,即当$dt \rightarrow 0$时,因$\hat{H}(t_0+dt) \rightarrow \hat{H}(t_0)$,故$\hat{U}(t_0+dt,t_0)=\hat{I}-\frac{\mathrm{i}}{\hbar} \hat{H}(t_0) dt$。</p><p>接下来,我们将仅作用微元时间的时间演化算符,拓展至作用有限且非无穷小时间的情形。仿照有限位移的位移算符的表达式,我们有:</p><script type="math/tex; mode=display">\hat{U}(t,t_0)=\lim_{n \rightarrow \infty} (\hat{I}-\frac{\mathrm{i}}{\hbar} \hat{H} \frac{t-t_0}{n})^n \nRightarrow \hat{U}(t,t_0)=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{H} (t-t_0)}</script><p>考虑到哈密尔顿算符$\hat{H}(t)$是一个随时间变化的算符,我们无法像位移算符那样,直接推出时间演化算符的表达式,事实上,只有当哈密尔顿算符不随时间变化时,$\hat{U}(t,t_0)=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{H} (t-t_0)}$才能成立。当然,如果哈密尔顿算符随时间变化,但每一时刻的哈密尔顿算符两两对易,即对于任意时刻$t_1, t_2 \in [t_0,t]$,有$[\hat{H}(t_1),\hat{H}(t_2)]=0$,则时间演化算符为$\hat{U}(t,t_0)=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \int^{t}_{t_0} \hat{H}(t’) dt’}$。</p><p>那么,当时间演化算符作用在态矢时,会发生什么呢?以作用微元时间的时间演化算符为例,根据定义,我们有</p><script type="math/tex; mode=display">\begin{align}&\quad \hat{U}(t+dt,t) | u(t) \rangle=| u(t+dt) \rangle \\ &\Rightarrow \big[ \hat{I}-\frac{\mathrm{i}}{\hbar} \hat{H}(t) dt \big] | u(t) \rangle=| u(t+dt) \rangle \\ &\Rightarrow | u(t) \rangle-\frac{\mathrm{i}}{\hbar} \hat{H}(t) dt | u(t) \rangle=| u(t+dt) \rangle \\ &\Rightarrow \hat{H}(t) | u(t) \rangle=\mathrm{i} \hbar \frac{| u(t+dt) \rangle-| u(t) \rangle}{dt}\end{align}</script><p>当$dt \rightarrow 0$时,上式变为$\hat{H}(t) | u(t) \rangle=\mathrm{i} \hbar \frac{\partial}{\partial t} | u(t) \rangle$,此即含时薛定谔方程。为讨论方便,在接下来的部分中,我们假设哈密尔顿算符不随时间变化,即$\hat{H}(t)=\hat{H}(0)=\hat{H}$,这样,随时间变化的便只有态矢$| u(t) \rangle$。设$t=0$时,哈密尔顿算符的本征态为$| u(t=0) \rangle=| E_i \rangle$,对应的体系总能量为$E_i$(即$\hat{H}(0) | u(0) \rangle=\hat{H} | E_i \rangle=E_i | E_i \rangle$),则经过一段时间$t$后,态矢将变为</p><script type="math/tex; mode=display">| u(t) \rangle=\hat{U}(t,0) | u(0) \rangle=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{H} t} | E_i \rangle=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} E_i t} | E_i \rangle \quad (\mathrm{since} \; \mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{H} t}=\sum\limits_{i=0}^{\infty} \frac{(-\frac{\mathrm{i} t}{\hbar})^i \hat{H}^i}{i!})</script><p>故除去相位差别外,$t$时刻的态矢$| u(t) \rangle$仍是哈密尔顿算符的本征态,记该态矢为$| E_i,t \rangle$,其满足$\hat{H}(t) | E_i,t \rangle=E_i | E_i,t \rangle$。相应的,对任意力学量$\hat{F}$,其在$t$时刻的期望值$\langle \hat{F} \rangle$为</p><script type="math/tex; mode=display">\langle \hat{F} \rangle(t)=\langle E_i,t | \hat{F} | E_i,t \rangle=(\langle E_i | \mathrm{e}^{\frac{\mathrm{i}}{\hbar} E_i t}) \hat{F} (\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} E_i t} | E_i \rangle)=\langle E_i | F | E_i \rangle</script><p>故<strong>力学量</strong>$\hat{F}$的<strong>期望值不随时间的变化而改变</strong>,从而在这一意义上,能量本征态被称为<strong>定态</strong>(此处隐含一个假设:<strong>力学量</strong>$\hat{F}$<strong>不随时间的变化而改变</strong>,而<strong>态矢随时间的变化而改变</strong>。这种对体系随时间演化的诠释,称为<strong>薛定谔图景</strong>)。</p><p>更进一步的,即或$| u(0) \rangle$不是任一能量本征态的基矢,仍可将其投影至能量本征态上:$| u(0) \rangle=\sum\limits_{i} | E_i \rangle \langle E_i | u(0) \rangle$,从而经$t$时间的演化后,该矢量变为</p><script type="math/tex; mode=display">| u(t) \rangle=\hat{U}(t,0) | u(0) \rangle=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{H} t} \sum\limits_{i} | E_i \rangle \langle E_i | u(0) \rangle=\sum\limits_{i} \mathrm{e}^{-\frac{\mathrm{i}}{\hbar} E_i t} | E_i \rangle \langle E_i | u(0) \rangle</script><p>上式表明,随着时间的流逝,$| u(t) \rangle$中各能量本征态的基矢的展开系数,将发生周期性(余弦)振荡,但其模长仍保持不变,因此,若对$| u(t) \rangle$测量能量,则<strong>得到某种能量本征值的概率仍不随时间变化而改变</strong>。</p><p>根据$| u(t) \rangle$的表达式,我们可以推出力学量$\hat{F}$在$t$时刻的期望值,以及该期望值对时间的任意阶微分:</p><script type="math/tex; mode=display">\begin{align}\langle \hat{F} \rangle(t) &= \langle u(t) | \hat{F} | u(t) \rangle=\sum\limits_{i} \sum\limits_{j} \big[ \mathrm{e}^{\frac{\mathrm{i}}{\hbar} E_i t} \langle u(0) | E_i \rangle \langle E_i | \big] \hat{F} \big[ \mathrm{e}^{-\frac{\mathrm{i}}{\hbar} E_j t} | E_j \rangle \langle E_j | u(0) \rangle \big] \\ &= \sum\limits_{i} \sum\limits_{j} \langle u(0) | E_i \rangle \langle E_j | u(0) \rangle \langle E_i | \hat{F} | E_j \rangle \mathrm{e}^{-\frac{\mathrm{i}}{\hbar} (E_j-E_i) t} \\\frac{d}{dt} \langle \hat{F} \rangle(t) &= \frac{d}{dt} \langle u(t) | \hat{F} | u(t) \rangle=\Big[ \frac{d \langle u(t) |}{dt} \Big] \hat{F} | u(t) \rangle+\langle u(t) | \hat{F} \Big[ \frac{d | u(t) \rangle}{dt} \Big] \\ &= \Big[ -\frac{1}{\mathrm{i} \hbar} \langle u(t) | \hat{H} \Big] \hat{F} | u(t) \rangle+\langle u(t) | \hat{F} \Big[ \frac{1}{\mathrm{i} \hbar} \hat{H} | u(t) \rangle \Big] \\ &= \frac{1}{\mathrm{i} \hbar} \langle u(t) | [\hat{F},\hat{H}] | u(t) \rangle \equiv \frac{1}{\mathrm{i} \hbar} \langle [\hat{F},\hat{H}] \rangle(t) \\\frac{d^2}{dt^2} \langle \hat{F} \rangle(t) &= \frac{1}{\mathrm{i} \hbar} \frac{d}{dt} \langle [\hat{F},\hat{H}] \rangle(t)=\frac{1}{\mathrm{i} \hbar} \cdot \frac{1}{\mathrm{i} \hbar} \langle u(t) | [[\hat{F},\hat{H}],\hat{H}] | u(t) \rangle \equiv \frac{1}{(\mathrm{i} \hbar)^2} \langle [[\hat{F},\hat{H}],\hat{H}] \rangle(t) \\&\dots \dots \\\frac{d^n}{dt^n} \langle \hat{F} \rangle(t) &= \frac{1}{(\mathrm{i} \hbar)^n} \langle u(t) | \underbrace{[[[\hat{F},\hat{H}],\dots],\hat{H}]}_{n层对易符号} | u(t) \rangle \equiv \frac{1}{(\mathrm{i} \hbar)^n} \langle \underbrace{[[[\hat{F},\hat{H}],\dots],\hat{H}]}_{n层对易符号} \rangle(t)\end{align}</script><p>上述方程的特殊情形之一,便是力学量算符$\hat{F}$取为位置算符$\hat{x}$,此时位置期望值的一阶微分为</p><script type="math/tex; mode=display">\begin{align}\frac{d}{dt} \langle \hat{x} \rangle(t) &= \frac{1}{\mathrm{i} \hbar} \langle [\hat{x},\hat{H}] \rangle(t)=\frac{1}{\mathrm{i} \hbar} \langle [\hat{x},\frac{\hat{p}^2}{2m}+V(\hat{x})] \rangle(t)=\frac{1}{\mathrm{i} \hbar} \big[ \langle [\hat{x},\frac{\hat{p}^2}{2m}] \rangle(t)+\langle [\hat{x},V(\hat{x})] \rangle(t) \big] \\ &= \frac{1}{\mathrm{i} \hbar} \langle (\frac{\hat{p}}{2m} [\hat{x},\hat{p}]+[\hat{x},\hat{p}] \frac{\hat{p}}{2m}) \rangle(t)=\frac{1}{\mathrm{i} \hbar} \frac{2 \mathrm{i} \hbar}{2m} \langle \hat{p} \rangle(t)=\frac{\langle \hat{p} \rangle(t)}{m}\end{align}</script><p>该式与牛顿力学中动量的定义式$p=mv=m \frac{dx}{dt}$具有相同的形式。此外,位置期望值的二阶微分为</p><script type="math/tex; mode=display">\begin{align}\frac{d^2}{dt^2} \langle \hat{x} \rangle(t) &= \frac{1}{m} \frac{d}{dt} \langle \hat{p} \rangle(t)=\frac{1}{m} \frac{1}{\mathrm{i} \hbar} \langle [\hat{p},\hat{H}] \rangle(t)=\frac{1}{\mathrm{i} \hbar m} \langle [\hat{p},\frac{\hat{p}^2}{2m}+V(\hat{x})] \rangle(t) \\ &= \frac{1}{\mathrm{i} \hbar m} \big[ \langle [\hat{p} ,\frac{\hat{p}^2}{2m}] \rangle+\langle [\hat{p},V(\hat{x})] \rangle \big]=\frac{1}{\mathrm{i} \hbar m} \langle [\hat{p},V(\hat{x})] \rangle\end{align}</script><p>设$V(\hat{x})=\sum\limits_{i=0}^{\infty} v_i \hat{x}^i$,则</p><script type="math/tex; mode=display">\begin{align}[\hat{p},V(\hat{x})] &= [\hat{p},\sum\limits_{i=0}^{\infty} v_i \hat{x}^i]=\sum\limits_{i=0}^{\infty} v_i [\hat{p},\hat{x}^i]=\sum\limits_{i=0}^{\infty} v_i (\hat{x} [\hat{p},\hat{x}^{i-1}]+[\hat{p},\hat{x}] \hat{x}^{i-1}) \\ &= \sum\limits_{i=0}^{\infty} v_i (\hat{x} [\hat{p},\hat{x}^{i-1}]-\mathrm{i} \hbar \hat{x}^{i-1})=\sum\limits_{i=0}^{\infty} v_i (\hat{x}^2 [\hat{p},\hat{x}^{i-2}]+\hat{x} [\hat{p},\hat{x}] \hat{x}^{i-2}-\mathrm{i} \hbar \hat{x}^{i-1}) \\ &= \sum\limits_{i=0}^{\infty} v_i (\hat{x}^2 [\hat{p},\hat{x}^{i-2}]-2 \mathrm{i} \hbar \hat{x}^{i-1})=\dots=-\mathrm{i} \hbar \sum\limits_{i=0}^{\infty} v_i i \hat{x}^{i-1}=-\mathrm{i} \hbar \frac{\partial V(\hat{x})}{\partial \hat{x}}\end{align}</script><p>从而位置期望值的二阶微分为$\frac{d^2}{dt^2} \langle \hat{x} \rangle(t)=-\frac{1}{m} \langle \frac{\partial V(\hat{x})}{\partial \hat{x}} \rangle$,或写作$m \frac{d^2}{dt^2} \langle \hat{x} \rangle(t)=-\langle \frac{\partial V(\hat{x})}{\partial \hat{x}} \rangle$,该方程称为艾伦<br>费斯特定理。</p><h4 id="I-10-电子自旋在均匀磁场中的进动"><a href="#I-10-电子自旋在均匀磁场中的进动" class="headerlink" title="[I-10] 电子自旋在均匀磁场中的进动"></a>[I-10] 电子自旋在均匀磁场中的进动</h4><p>在本篇的末尾,我们以电子自旋在均匀磁场中的进动作结,同时为下一篇中用量子力学阐述核磁共振的脉冲序列及其效应作铺垫。</p><p>电子是自旋数为$s=\frac{1}{2}$的费米子,其自旋磁量子数为$m_s=\pm \frac{1}{2}$,因此自旋本征态(或称$\hat{S}^2$与$\hat{S}_z$的共同本征矢)为$| s=\frac{1}{2},m_s=\frac{1}{2} \rangle$和$| s=\frac{1}{2},m_s=-\frac{1}{2} \rangle$,简记为$| s_z+ \rangle$和$| s_z- \rangle$。为书写方便,我们还可以将$| s_z+ \rangle$进一步简记为$| \alpha \rangle$,并根据自旋磁量子数的符号,称为“<strong>自旋向上</strong>”;类比可得$| s_z- \rangle$进一步简记为$| \beta \rangle$,并称为“<strong>自旋向下</strong>”。</p><p>现在,我们对电子施加一个均匀恒定的磁场$\boldsymbol{B}$,根据电动力学的经验,我们可以写出电子自旋在均匀磁场中的哈密顿算符:$\hat{H}=\boldsymbol{\hat{\mu}} \cdot \boldsymbol{B}=-\frac{g_s e}{2 m} \hat{\boldsymbol{S}} \cdot \boldsymbol{B}$,取均匀磁场方向为$z$方向,则$\hat{H}=-\frac{g_s e B}{2 m} \hat{S}_z \equiv \omega \hat{S}_z$,其中$\omega=-\frac{g_s e B}{2 m}$为电子自旋的进动频率。显然,$\hat{H}$的本征态就是$\hat{S}_z$的本征态,且相应的能量本征值为$E_{\pm}=\pm \frac{1}{2} \hbar \omega$ ,故从零时刻开始,经一段时间$t$演化,对应的演化算符为$\hat{U}(t,0)=\mathrm{e}^{-\frac{\mathrm{i}}{\hbar} \hat{H} t}=\mathrm{e}^{-\frac{\mathrm{i} \omega t}{\hbar} \hat{S}_z}$。记初始时刻($t=0$)态矢为$| u(0) \rangle=c_{\alpha} | \alpha \rangle+c_{\beta} | \beta \rangle$,则演化$t$时后,态矢将变为</p><script type="math/tex; mode=display">\begin{align}| u(t) \rangle &= \hat{U}(t,0) | u(0) \rangle=\mathrm{e}^{-\frac{\mathrm{i} \omega t}{\hbar} \hat{S}_z} (c_{\alpha} | \alpha \rangle+c_{\beta} | \beta \rangle) \\ &= c_{\alpha} \mathrm{e}^{-\frac{\mathrm{i} \omega t}{\hbar} \cdot \frac{\hbar}{2}} | \alpha \rangle+c_{\beta} \mathrm{e}^{-\frac{\mathrm{i} \omega t}{\hbar} \cdot (-\frac{\hbar}{2})} | \beta \rangle \\ &= c_{\alpha} \mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle+c_{\beta} \mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} | \beta \rangle\end{align}</script><p>假设电子处于能量本征态之一——自旋向上,即$| u(0) \rangle=| \alpha \rangle$,则有$c_{\alpha}=1$, $c_{\beta}=0$,故$| u(t) \rangle=\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle$,表明无论过多长时间,该电子在均匀磁场中均保持自旋向上的状态,改变的仅仅是矢量的相位,这一结论对于自旋向下的初态亦成立。</p><p>倘若电子不是处于能量本征态,而是处于叠加态呢?例如,电子处于$\hat{S}_x$本征态$| u(0) \rangle=| s_x+ \rangle=\frac{1}{\sqrt{2}} (| \alpha \rangle+| \beta \rangle)$,此时$c_{\alpha}=c_{\beta}=\frac{1}{\sqrt{2}}$,故演化$t$时后,态矢将变为$| u(t) \rangle=\frac{1}{\sqrt{2}} (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} | \beta \rangle)$,对比电子为自旋向上的情形,我们发现,当电子处于叠加态时,随着时间的流逝,自旋向上部分与自旋向下部分的相位向相反方向演化,这将影响到电子处于每种$\hat{S}_x$本征态的概率。事实上,进一步的计算表明</p><script type="math/tex; mode=display">\begin{align}P(s_x \pm,t) &= \big| \langle s_x \pm | u(t) \rangle \big|^2=\big| \frac{1}{\sqrt{2}} (\langle \alpha | \pm \langle \beta |) \cdot \frac{1}{\sqrt{2}} (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} | \beta \rangle) \big|^2 \\ &= \big| \frac{1}{2} (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \pm \mathrm{e}^{\frac{\mathrm{i} \omega t}{2}}) \big|^2=\Big| \frac{1}{2} \big[ (\cos{\frac{\omega t}{2}}-\mathrm{i} \sin{\frac{\omega t}{2}}) \pm (\cos{\frac{\omega t}{2}}+\mathrm{i} \sin{\frac{\omega t}{2}}) \big] \Big|^2 \\ &= \begin{cases} \cos^2{\frac{\omega t}{2}} \quad (\mathrm{for} \; | s_x+ \rangle) \\ \sin^2{\frac{\omega t}{2}} \quad (\mathrm{for} \; | s_x- \rangle) \end{cases}\end{align}</script><p>即处于$| s_x+ \rangle$与$| s_x- \rangle$的概率呈余弦(正弦)相关函数的形式。此外,若电子的初始自旋状态为$| s_x+ \rangle$,则演化至$t$时,各自旋角动量的分量的期望值为</p><script type="math/tex; mode=display">\begin{align}\langle \hat{S}_x \rangle(t) &= \langle u(t) | \hat{S}_x | u(t) \rangle=\Big[ \frac{1}{\sqrt{2}} (\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \langle \alpha |+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \langle \beta |) \Big] \hat{S}_x \Big[ \frac{1}{\sqrt{2}} (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} | \beta \rangle) \Big] \\&= \frac{1}{2} (\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \langle \alpha |+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \langle \beta |) (\mathrm{e}^{-\frac{\mathrm{i} \omega t} {2}} \cdot \frac{\hbar}{2} | \beta \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \cdot \frac{\hbar}{2} | \alpha \rangle) \\&= \frac{\hbar}{4} (\mathrm{e}^{-\mathrm{i} \omega t}+\mathrm{e}^{\mathrm{i} \omega t})=\frac{\hbar}{4} \cdot 2 \cos{\omega t}=\frac{\hbar}{2} \cos{\omega t} \\\langle \hat{S}_y \rangle(t) &= \langle u(t) | \hat{S}_y | u(t) \rangle=\Big[ \frac{1}{\sqrt{2}} (\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \langle \alpha |+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \langle \beta |) \Big] \hat{S}_y \Big[ \frac{1}{\sqrt{2}} (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} | \beta \rangle) \Big] \\&= \frac{1}{2} (\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \langle \alpha |+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \langle \beta |) (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \cdot \frac{\mathrm{i} \hbar}{2} | \beta \rangle+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \cdot \frac{-\mathrm{i} \hbar}{2} | \alpha \rangle) \\&= \frac{\mathrm{i} \hbar}{4} (\mathrm{e}^{-\mathrm{i} \omega t}-\mathrm{e}^{\mathrm{i} \omega t})=\frac{\mathrm{i} \hbar}{4} \cdot (-2 \mathrm{i} \sin{\omega t})=\frac{\hbar}{2} \sin{\omega t} \\\langle \hat{S}_z \rangle(t) &= \langle u(t) | \hat{S}_z | u(t) \rangle=\Big[ \frac{1}{\sqrt{2}} (\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \langle \alpha |+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \langle \beta |) \Big] \hat{S}_z \Big[ \frac{1}{\sqrt{2}} (\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} | \alpha \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} | \beta \rangle) \Big] \\&= \frac{1}{2} (\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \langle \alpha |+\mathrm{e}^{-\frac{\mathrm{i} \omega t}{2}} \langle \beta |) (\mathrm{e}^{-\frac{\mathrm{i} \omega t} {2}} \cdot \frac{\hbar}{2} | \alpha \rangle+\mathrm{e}^{\frac{\mathrm{i} \omega t}{2}} \cdot \frac{-\hbar}{2} | \beta \rangle) \\&= \frac{\hbar}{4} (1-1)=0\end{align}</script><p>以上推导表明,当电子的初始自旋状态为$| s_x+ \rangle$时,自旋角动量在$x$轴(或$y$轴)的分量的期望值按照余弦(正弦)函数变化,而$z$轴分量始终为零,这与自旋角动量在$xy$平面上绕$z$轴转动的图景是一致的。</p><h3 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h3><p>(从略,视更新情况补充,咕咕咕)</p>]]></content>
<categories>
<category> 核磁共振波谱 </category>
</categories>
<tags>
<tag> 核磁共振波谱 </tag>
<tag> 量子力学 </tag>
</tags>
</entry>
<entry>
<title>Gaussian 16 & GaussView 6安装教程</title>
<link href="/2022/11/17/Gaussian-installation-tutorial/"/>
<url>/2022/11/17/Gaussian-installation-tutorial/</url>
<content type="html"><![CDATA[<p>【最近在Ubuntu服务器上安装GaussView 6频繁报错,最后发现是渲染软件的问题,只能说今天实在爆炸(此处应有大声咆哮)】</p><p>【真的,但凡Linux你统一一下系统库文件的标准命名,加一个人性化的报错提示,也不至于让我找缺失哪个包找半天】</p><h4 id="Part-I-Gaussian-16的安装与环境变量的配置"><a href="#Part-I-Gaussian-16的安装与环境变量的配置" class="headerlink" title="Part I. Gaussian 16的安装与环境变量的配置"></a>Part I. Gaussian 16的安装与环境变量的配置</h4><p>最详细的安装教程,请参考卢天(@sobereva)撰写的博客文章<strong><a href="http://sobereva.com/439">Gaussian的安装方法及运行时的相关问题</a></strong>,以下安装过程仅在此文章基础上稍加调整。</p><ol><li>将Gaussian安装包G16-B01_DownLoadLy.iR.tar.gz放在公共软件根目录/smb/open-apps下,输入下列命令将其解压,得到文件夹g16:</li></ol><pre><code class="lang-bash">tar -xzvf G16-B01_DownLoadLy.iR.tar.gz</code></pre><ol><li>建立一个文件夹用于储存Gaussian运行过程中产生的临时文件,位置随意。此处笔者将临时文件夹放在g16下,其位置为/smb/open-apps/g16/scratch</li><li>修改个人环境变量,以测试g16能否正常运行:用vi或者gedit等文本编辑器打开/home/lizh/.bashrc(笔者的bash环境变量),在里面加入以下语句然后保存文件。</li></ol><pre><code class="lang-bash">export g16root=/smb/open-apps/export GAUSS_SCRDIR=/smb/open-apps/g16/scratchsource /smb/open-apps/g16/bsd/g16.profile</code></pre><p>其中,g16root环境变量用来说明Gaussian目录被放在了哪个目录下。GAUSS_SCRDIR环境变量用来说明哪个文件夹作为临时文件夹。source命令用来执行Gaussian自带的脚本文件,内含各种配置Gaussian运行环境的命令。重新进入终端使以上内容生效(如果你是用Linux图形环境,就关闭终端窗口,然后重新打开。如果你是通过ssh方式登录服务器,就断开连接,然后重新连接服务器)</p><ol><li>Gaussian目录下的Default.Route用来设定默认用的计算资源,-M-设置默认用的最大内存量(一般用MB或GB为单位),-P-设置默认用多少CPU核数来并行计算。比如我们想默认用24个核心、最大40GB内存做计算,就在/smb/open-apps/g16/Default.Route里面写入以下内容</li></ol><pre><code class="lang-bash">-M- 40GB-P- 24</code></pre><p>此文件中的设置优先级低于输入文件里的%mem和%nproc设置。因此,输入文件里没写%mem的时候才会用这里的-M-设置,输入文件里没写%nproc的时候才会使用这里的-P-设置(如果你既没在这里设-P-也没写%nproc,那么程序只用单核计算。如果你既没在这里设-M-也没写%mem,那么G09最多用256MB内存,G16最多用800MB内存)。</p><ol><li>为保证只有特定用户组才能使用Gaussian 16,我们可以用groupadd命令创建一个新组:</li></ol><pre><code class="lang-bash">groupadd tanglab</code></pre><p>再将每一个新用户加入进tanglab用户组(此处的(username)代表要改动的用户名):</p><pre><code class="lang-bash">usermod -G -a tanglab (username)</code></pre><p><em>命令,之后Gaussian就可以使用了。这里-R </em><em>命令,之后Gaussian就可以使用了。这里-R </em>ian就可以使用了。这里-R *代表对当前目录下所有文件和所有子目录下的文件都设置权限。对于其下的/scratch,由于Gaussian 16要读写此处的临时文件,因此运行chmod 775 -R /scratch,让同一用户组的所有用户都能读写此文件夹和其中的文件。</p><ol><li>用sudo vim /etc/bash.bashrc打开bash.bashrc文件,将/home/lizh/.bashrc中写入的Gaussian环境变量复制到其中,保存后输入source /etc/bash.bashrc并运行,以设置全局环境变量。</li></ol><h4 id="Part-II-GaussView-6的安装与环境变量的配置"><a href="#Part-II-GaussView-6的安装与环境变量的配置" class="headerlink" title="Part II. GaussView 6的安装与环境变量的配置"></a>Part II. GaussView 6的安装与环境变量的配置</h4><ol><li>将GaussView安装包gv6.tar.bz2放在公共软件根目录/smb/open-apps下,输入下列命令将其解压,得到文件夹gv</li></ol><pre><code class="lang-bash">tar -xjvf gv6.tar.bz2</code></pre><ol><li>修改个人环境变量,以测试GaussView能否正常运行:用vi或者gedit等文本编辑器打开/home/lizh/.bashrc(笔者的bash环境变量),在里面加入以下语句然后保存文件。</li></ol><pre><code class="lang-bash">export GV_DIR=/smb/open-apps/gv/export LIBPATH=/smb/open-apps/gvexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/smb/open-apps/gv/libPATH=$PATH:/smb/open-apps/gvalias gv='/smb/open-apps/gv/gview.sh'</code></pre><p>重新进入终端,或运行source .bashrc,使以上内容生效。如果环境变量配置正确,便能正常弹出GaussView 6的工作界面。</p><ol><li>用sudo vim /etc/bash.bashrc打开bash.bashrc文件,将/home/lizh/.bashrc中写入的Gaussian环境变量复制到其中,保存后输入source /etc/bash.bashrc并运行,以设置全局环境变量。</li></ol><h4 id="Part-III-故障排除:GaussView-6在图形界面下能运行,在MobaXterm的远程客户端却无法运行"><a href="#Part-III-故障排除:GaussView-6在图形界面下能运行,在MobaXterm的远程客户端却无法运行" class="headerlink" title="Part III. 故障排除:GaussView 6在图形界面下能运行,在MobaXterm的远程客户端却无法运行"></a>Part III. 故障排除:GaussView 6在图形界面下能运行,在MobaXterm的远程客户端却无法运行</h4><p>然而,离奇的事情总是发生在安装完成之后——当笔者在MobaXterm的远程客户端上,向bash命令行输入gv并回车后,客户端先是卡顿片时,随后弹出一个白色小框(对应于GaussView的欢迎界面)后迅速消失,并报出如下错误:segmentation fault (core dumped)。笔者以为能在GaussView的安装根目录找到转储文件,访问gv文件夹后却一无所获。</p><p><strong>初步排查:</strong>笔者首先怀疑是下载的安装包可能损坏,导致部分文件无法使用,于是从另一个装有GaussView 6的服务器上拷贝了整份GaussView 6,并上传到出现Bug的服务器上,以替换原来的GaussView 6。结果很可惜,运行gv命令后GaussView仍无法打开,且显示的错误仍然为segmentation fault (core dumped)。笔者随后怀疑配置的环境变量写法有问题,因此把export GV_DIR=/smb/open-apps/gv/改为export GV_DIR=/smb/open-apps/gv/bin,export LIBPATH=/smb/open-apps/gv改为export LIBPATH=/smb/open-apps/gv/lib,但重新加载环境变量文件后,发现问题仍然没有解决。</p><p>于是笔者想到:会不会在带有GUI的服务器端运行,也会出现同样的问题?于是笔者第二天一早,便登录服务器端的图形界面,并在该界面中打开终端,输入gv后回车。令人惊讶的是,执行命令后,屏幕上直接跳出了GaussView的欢迎界面,随后便加载出GaussView的菜单和绘制区域。这让我更加疑惑:既然在图形界面下能正常加载窗口,那为什么到只有文字的MobaXterm终端,GaussView就不能运行?</p><p>而后,同实验室的同学(江意达)用他自己的账户,在MobaXterm上同样试运行了gv,结果同样出现了白色方框闪现后消失,且主界面未能成功加载的错误,但是反馈的错误信息不是“segmentation fault (core dumped)”,而是“can’t connect to x11 window server using localhost:0.0”(记不清了,总之大致意思是X11未能成功连接,导致GaussView无法运行)。这样,问题基本锁定在MobaXterm上:正是MobaXterm缺乏某种必要的库文件,才导致X11无法成功连接,进而无法运行GaussView 6的图形界面。(后记:意达告诉笔者,X11没能成功连接,是因为没有登入正确账户)</p><p>但是,在昨晚的故障排查中,笔者已经装过X11相关的所有必要文件(包括库文件等),而错误仍然没有消除,因此X11不是导致故障的主要原因。由此,整个故障排查陷入僵局。</p><p><strong>问题根源:</strong>后来,在搜寻X11导致的GaussView报错的案例时,我发现了<a href="https://csc.cnsi.ucsb.edu/docs/gaussview">UCSB计算中心对这一错误的介绍和解决方案</a>:</p><blockquote><p><strong><em>Note: As of 2016, if you are having trouble with Gaussview starting, with errors about “X11”, “XQuarta” or “OpenGL is not available”, try to type this first.</em></strong></p><p><strong><em>export USE_MESAGL=1</em></strong></p></blockquote><p>于是笔者怀疑,看起来是X11导致的GaussView 6崩溃,其实<strong>很可能是OpenGL未能正确加载所引起的结果!</strong>由于适配于Ubuntu的OpenGL,实际上为开源软件MesaGL,而GaussView在默认情况下,只会调用OpenGL,而不会调用MesaGL,因此绘制软件窗口时,就会因为没有图形引擎而无法完成,进而报错。因此,只要让GaussView启动时,自动加载MesaGL,便能正确绘制图形界面,继而消除该错误。当然,对于“图形界面下能正常加载GaussView,而纯命令行窗口不能”这一问题,笔者认为,图形界面下,OpenGL/MesaGL已经处于开启状态,当用户输入命令启动GaussView时,GaussView会自动调用启动的OpenGL/MesaGL,以加载图形窗口,因此不会报错,而纯命令行下不会自动开启OpenGL/MesaGL,因此启动GaussView会报错。</p><p><strong>解决方案:</strong>根据上述分析,笔者很快得到了解决方案:在/home/lizh/.bashrc(本地用户环境变量)或/etc/bash.bashrc(全局环境变量)中,加入export USE_MESAGL=1,这样,即使使用的是纯命令行界面,当输入gv并回车后,也会启动系统安装的MesaGL,这样就解决了因缺乏图形引擎导致的故障。</p><p><strong>补充说明——如何安装MesaGL库:</strong>以Ubuntu为例,首先要安装必要的编译器,这样才能在后续的安装过程中,编译源码文件:</p><pre><code class="lang-bash">sudo apt-get install build-essential</code></pre><p>接着是安装OpenGL运行库(OpenGL Library,实质为MesaGL Library)</p><pre><code class="lang-bash">sudo apt-get install libgl1-mesa-dev</code></pre><p>然后是安装OpenGL效用库(OpenGL Utilities,实质为MesaGL Utilities)</p><pre><code class="lang-bash">sudo apt-get install libglu1-mesa-dev</code></pre><p>以及安装OpenGL效用库工具(OpenGL Utility Toolkit,实质为MesaGL Utility Toolkit)</p><pre><code class="lang-bash">sudo apt-get install freeglut3-dev</code></pre><p>如果怕缺失关键的库文件,可以试着运行下列命令</p><pre><code class="lang-bash">sudo apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-devsudo apt-get install libglfw3-dev libglfw3</code></pre><p>这样应该能保证MesaGL库安装完全。</p><p><strong>参考资料:</strong></p><p><a href="https://blog.csdn.net/qq_40520596/article/details/111663646">Ubuntu安装OpenGL</a></p><p><a href="https://blog.csdn.net/liubing8609/article/details/102863044?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-4-102863044-blog-111663646.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-4-102863044-blog-111663646.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=7">Ubuntu上安装OpenGL</a></p><p><a href="https://jieniyimiao.blog.csdn.net/article/details/44569337?spm=1001.2101.3001.6650.12&utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~Rate-12-44569337-blog-102863044.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~Rate-12-44569337-blog-102863044.pc_relevant_default&utm_relevant_index=13">Ubuntu 13.04 安装 OpenGL</a></p><p><a href="https://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Linux">OpenGL Programming/Installation/Linux</a></p>]]></content>
<categories>
<category> 计算化学 </category>
</categories>
<tags>
<tag> 量子化学 </tag>
<tag> 计算化学 </tag>
<tag> Gaussian </tag>
</tags>
</entry>
<entry>
<title>基于NMRPipe的RDC数据处理教程</title>
<link href="/2022/11/17/RDC-data-processing-tutorial/"/>
<url>/2022/11/17/RDC-data-processing-tutorial/</url>
<content type="html"><![CDATA[<h4 id="0-预备知识"><a href="#0-预备知识" class="headerlink" title="0. 预备知识"></a>0. 预备知识</h4><p><strong>残余偶极耦合(Residual Dipolar Coupling,RDC)</strong>是一种基于核磁共振的表征手段,常用于蛋白质动态结构的辅助解析与验证,其原理为:空间上相互邻近,但不具备化学键连的偶极(如<sup>1</sup>H-<sup>15</sup>N原子对)之间,存在直接的电磁相互作用,在溶液中,偶极朝不同方向的分布相同,因而偶极-偶极相互作用平均值为零,无法直接观测;而在液晶或聚合物孔洞等定向程度高的环境,偶极朝不同方向的分布有差异,因此偶极-偶极相互作用平均值不为零(这是“残余(剩余)”一词的由来),表现为J耦合形成的裂分进一步增大或减小,其大小与偶极间的相对朝向有关,故可用于获取化学键的空间取向,以修正蛋白质结构。</p><p>通常情况下,测定RDC的常用核磁方法为<strong>IPAP-HSQC</strong>,这是一种自旋态选择性HSQC实验,通过在特定时间点交替施加和撤去脉冲,在消除直接维裂分的同时,将间接维裂分转变为方向相同的In-Phase分量和方向相反的Anti-Phase分量,再通过谱图加减,得到记录在不同图谱的高场分量与低场分量,避免信号峰相互叠加,从而大大降低RDC效应的测量难度,其原理大致如图1所示。</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig1.png" style="zoom: 50%;"></center><center><strong>图1</strong> IPAP-HSQC测定RDC示意图</center><p><strong>NMRPipe</strong>是由John Marino课题组与Ad Bax课题组联合开发的,适用于Unix及衍生系统的老牌核磁共振谱图处理软件。利用NMRPipe,可以把获得的原始IPAP谱图,拆分为独立的高场与低场分量,并能对拆分后的谱图进行相位调整、峰标记与峰归属(在预先准备归属文件的前提下)。</p><p>不过,由于NMRPipe并未将所有功能集成在一个GUI界面,而是采用命令行与简陋GUI相结合的方式,这对习惯于Windows的用户而言,无疑增加了操作难度,因此,笔者试着整理了一份基于NMRPipe的RDC数据处理教程,希望对NMRPipe新人有所帮助。</p><h4 id="I-NMRPipe的安装"><a href="#I-NMRPipe的安装" class="headerlink" title="I. NMRPipe的安装"></a>I. NMRPipe的安装</h4><p><strong>1. 安装包下载:</strong>访问<a href="https://www.ibbr.umd.edu/nmrpipe/install.html">NMRPipe官网</a>,下载四个文件:NMRPipeX.tZ(NMRPipe源文件)、s.tZ(NMRPipe补丁和更新文件)、install.com(安装脚本)、binval.com(配合安装脚本使用的脚本)。如有需要,可以下载另外几个补充包:dyn.tZ(似乎用于在TALOS+中绘制拉氏图,同时存有DYNAMO and MFR),talos_nmrPipe.tZ(TALOS-N, TALOS+, and SPARTA+的必要运行文件),plugin.smile.tZ(SMILE NUS谱图重构程序)。</p><p><strong>2. 将终端切换为C-shell:</strong>输入chsh -s /bin/tcsh,回车(没有tcsh/csh的情况下,首先用sudo yum(for RHEL-based Linux)/apt-get(for Ubuntu) install -y)。</p><p><strong>3. 安装运行时必要的库文件:</strong>若为Cent OS 7,首先以root权限登录,找到/etc/yum.conf,添加multilib_policy=all并保存,然后切换为普通用户,分别输入以下命令并回车:</p><pre><code class="lang-bash">sudo yum install -y xtermsudo yum install -y libgccsudo yum install -y glibcsudo yum install -y libX11.so.6sudo yum install -y libXextsudo yum install -y libstdc++sudo yum install -y xorg-x11-fonts-75dpisudo yum install -y xorg-x11-fonts-ISO8859-1-75dpi</code></pre><p>这样就安装好运行时必要的库文件</p><p><strong>(补充于2022.10)</strong>若为Ubuntu,所需的软件包和对应的名称与Cent OS有显著不同,因此运行的命令改为</p><pre><code class="lang-bash">sudo apt-get install tcshsudo apt-get install xtermsudo apt-get install lib32z1sudo apt-get install libx11-6:i386sudo apt-get install libxext6:i386sudo apt-get install xfonts-75dpisudo apt-get install msttcorefonts</code></pre><p>要注意的是,安装msttcorefonts时,在命令行下会弹出一个EULA协议的窗口,类似于下图所示,此时需要按Tab键,让光标转到《OK》上,然后回车,接下来按方向键,使光标停在《YES》上,回车即可。</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/muo-linux-ms-fonts-eula.webp" style="zoom: 80%;"></center><center><strong>图1.5</strong> 万恶的EULA协议,害得我不知道怎么进行下一步操作</center><p><strong>4. 更改文件读写权限并安装:</strong>将四个文件放入指定文件夹中(如/home/(你的用户名)/NMRPipe),在该文件夹打开终端,输入:</p><pre><code class="lang-bash">chmod a+r *.tZ *.Z *.tarchmod a+rx *.com</code></pre><p>然后在当前terminal里输入xterm,回车;在新的xterm的窗口中输入./install.com,回车</p><p><strong>5. 测试:</strong>退出终端,再重新打开终端,输入以下命令并回车,以测试NMRPipe运行情况:</p><pre><code class="lang-bash">which nmrPipe (Check that programs can be found)nmrPipe -help (Run program in help mode)man nmrPipe (Check manual pages)bruker (varian delta) (Run the graphical conversion interface)nmrDraw (Run the graphical interface)</code></pre><p>若以上命令能正常运行,即表明NMRPipe安装成功</p><p><strong>注意:</strong>按以上步骤安装,通常会将.cshrc一并配置,如果没有配置,请将以下代码粘贴至.cshrc</p><pre><code class="lang-bash">#!/bin/csh if (-e /home/clemmensen/workbench/NMRPipe/com/nmrInit.linux212_64.com) then source /home/clemmensen/workbench/NMRPipe/com/nmrInit.linux212_64.com endif if (-e /home/clemmensen/workbench/NMRPipe/com/font.com) then source /home/clemmensen/workbench/NMRPipe/com/font.com endif</code></pre><h4 id="II-用NMRPipe处理IPAP-HSQC谱,并获取RDC数据"><a href="#II-用NMRPipe处理IPAP-HSQC谱,并获取RDC数据" class="headerlink" title="II. 用NMRPipe处理IPAP-HSQC谱,并获取RDC数据"></a>II. 用NMRPipe处理IPAP-HSQC谱,并获取RDC数据</h4><p><strong>1.图谱格式转换:</strong>在原始图谱的文件夹中打开终端,输入bruker,回车,接下来会弹出如下窗口</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig2.png" style="zoom: 45%;"></center><center><strong>图2</strong> 运行bruker后弹出的窗口</center>点击红框中的“Read Parameters”,程序将读入图谱中的各项参数。接下来按照图片顺序,点击红框,调整各项参数<center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig3.png" style="zoom: 45%;"></center><center><strong>图3</strong> 对bruker参数的设定(1)</center><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig4.png" style="zoom: 45%;"></center><center><strong>图4</strong> 对bruker参数的设定(2)</center>最后先后点击“Save Script”→“Execute Script”,完成图谱转换,得到test.fid<center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig5.png" style="zoom: 45%;"></center><center><strong>图5</strong> 运行bruker生成的转换脚本</center><p><strong>2.图谱的初步处理(HSQC及其衍生谱必做!)</strong></p><p>将处理脚本hsqc.com复制到原始图谱的文件夹中,接着输入下列命令,赋予当前用户读写和运行脚本的权限,且能以可执行文件运行。(以后若不说明,所有.com脚本从本地上传至服务器后,或从Windows传至Linux虚拟机后,均执行此步骤)</p><pre><code class="lang-bash">chmod +755 hsqc.com</code></pre><p>然后在终端中输入./hsqc.com,回车,得到初步处理后的二维图谱。</p><p>这样处理的图谱相位未必准确,所以我们要在NMRDraw中微调相位,使基线平齐,然后在hsqc.com中修改相位参数,再重复上述步骤。</p><p>在原始图谱的文件夹打开终端,输入nmrDraw,回车,会弹出如下窗口,此时右键单击“File”→“S) Select File”:</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig6.png" style="zoom: 30%;"></center><center><strong>图6</strong> 运行nmrDraw后弹出的窗口</center>便会弹出一个“打开文件”的窗口,双击选中test.ft2,然后点击窗口下部分的Read/Draw按钮,便会绘制出初步调整后的HSQC谱。<center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig7.png" style="zoom: 30%;"></center><center><strong>图7</strong> 单击“S) Select File”后弹出的窗口</center><p>按H键,打开水平轴(<sup>1</sup>H)的NMR谱,点击图上信号明显的峰(尽量选取水平线上峰数较少的位置),便可查看点击位置水平线上的核磁信号;同理,按V键打开的是垂直轴(<sup>15</sup>N)的NMR谱。选取合适的基线参照位置后,可以拖动左上方工具栏的滑块(如红框所示),调节0阶和1阶校正的参数大小,或是直接输入具体数值调节。待基线平整,且信号峰显著,无杂峰干扰后,退出NMRDraw,修改.hsqc中相位校正的参数,然后重新运行.hsqc</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig8.png" style="zoom: 30%;"></center><center><strong>图8</strong> 在nmrDraw中预先调整谱图相位</center><p><strong>附:fid.com的代码(代码不唯一,以bruker命令生成的为准)</strong></p><pre><code class="lang-bash">#!/bin/cshbruk2pipe -verb -in ./ser \ -bad 0.0 -ext -aswap -AMX -decim 2080 -dspfvs 20 -grpdly 67.9842071533203 \ -xN 1024 -yN 320 \ -xT 512 -yT 160 \ -xMODE DQD -yMODE Complex \ -xSW 9615.385 -ySW 2189.142 \ -xOBS 600.133 -yOBS 60.818 \ -xCAR 4.725 -yCAR 118.037 \ -xLAB HN -yLAB 15N \ -ndim 2 -aq2D Complex \| nmrPipe -fn MULT -c 3.90625e+00 \ -out ./test.fid -ovsleep 5</code></pre><p><strong>附:hsqc.com的代码</strong></p><pre><code class="lang-bash">#!/bin/cshnmrPipe -in test.fid \ \| nmrPipe -fn SP -off 0.5 -end 0.98 -pow 1 -c 1 \| nmrPipe -fn ZF -auto \| nmrPipe -fn FT \| nmrPipe -fn PS -p0 -12.5 -p1 0 -di \| nmrPipe -fn EXT -x1 11ppm -xn 6.0ppm -sw -verb \| nmrPipe -fn TP \| nmrPipe -fn SP -off 0.5 -end 0.98 -pow 1 -c 0.5 \| nmrPipe -fn ZF -auto \| nmrPipe -fn FT \| nmrPipe -fn PS -p0 0 -p1 0 -di \| nmrPipe -fn POLY -auto \| nmrPipe -fn TP \| nmrPipe -fn POLY -auto \ -verb -ov -out test.ft2nmrPipe -in test.ft2| pipe2xyz -nv -out hsqc.nv -verb -ov</code></pre><p><strong>上述代码解释与注意事项</strong>:(1)-fn代表功能选项,SP代表窗函数,-pow为1时使用正弦窗函数,-pow为2时使用正弦方形窗函数,-c代表第一个点的放大倍数(?),ZF代表充零,FT代表傅里叶变换,PS代表相位校正,-p0为0阶校正,-p1为1阶校正,EXT代表提取部分图谱,-x1和-xn分别规定提取图谱的左右边界,TP代表数据转置(如x轴到y轴);傅里叶变换时默认从x轴(1H)开始处理<br>(2)第一处的相位校正调整的是1H的基线,第二处的相位校正调整的是15N的基线<br>(3)最后一行命令的目的,是将test.ft2通过pipe2xyz转换为NMRViewJ能识别的hsqc.nv,若不需要,可在前面加上#,这样该命令就会变成注释,不会自动执行<br>(4)有时候会发现初步处理的图谱如同从中间剪开后,再沿着没有剪的边拼合一般,此时我们应该把第二次出现的nmrPipe -fn FT改为nmrPipe -fn FT -alt</p><p><strong>3.IPAP谱的分裂和谱图加减(IPAP谱必做!其他谱图跳过)</strong></p><p>将处理脚本2p-pre.com复制到原始图谱的文件夹中,接着修改脚本权限,使脚本对所有用户均可读写执行,且能以可执行文件运行(以后涉及脚本处理时默认执行此步骤)。然后打开终端,输入./2p-pre.com,回车,生成分裂后的IPAP谱testA.ft2和testB.ft2。</p><p>接下来在终端输入如下代码并执行:</p><pre><code class="lang-bash">addNMR -in1 testA.ft2 -in2 testB.ft2 -add -out add.ft2 addNMR -in1 testA.ft2 -in2 testB.ft2 -sub -out sub.ft2</code></pre><p>生成相加的图谱add.ft2和相减的图谱sub.ft2</p><p>同样要注意的是,按默认参数生成的add.ft2和sub.ft2相位可能存在较大偏差,导致最终在图上呈现的峰并非均一的单峰,甚至杂乱无章,此时需要按照第2部分所述调整水平轴(<sup>1</sup>H)和垂直轴(<sup>15</sup>N)的相位,然后在2p-pre.com中修改相位调整语句的参数,再重新运行2p-pre.com,最后对谱图加减。</p><p><strong>附:2p-pre.com的代码</strong></p><pre><code class="lang-bash">#!/bin/cshnmrPipe -in test.fid \| nmrPipe -fn COADD -time -axis Y -cList 1 0\| nmrPipe -fn SP -off 0.5 -end 0.98 -pow 1 -c 1 \| nmrPipe -fn ZF -auto \| nmrPipe -fn FT \| nmrPipe -fn PS -p0 180 -p1 0 -di \| nmrPipe -fn EXT -x1 12ppm -xn 5.5ppm -sw -verb \| nmrPipe -fn TP \| nmrPipe -fn SP -off 0.5 -end 0.98 -pow 1 -c 0.5 \| nmrPipe -fn ZF -auto \| nmrPipe -fn FT -alt \| nmrPipe -fn PS -p0 0 -p1 0 -di \| nmrPipe -fn POLY -auto \| nmrPipe -fn TP \| nmrPipe -fn POLY -auto \ -verb -ov -out testA.ft2nmrPipe -in test.fid \| nmrPipe -fn COADD -time -axis Y -cList 0 1\| nmrPipe -fn SP -off 0.5 -end 0.98 -pow 1 -c 1 \| nmrPipe -fn ZF -auto \| nmrPipe -fn FT \| nmrPipe -fn PS -p0 180 -p1 0 -di \| nmrPipe -fn EXT -x1 12ppm -xn 5.5ppm -sw -verb \| nmrPipe -fn TP \| nmrPipe -fn SP -off 0.5 -end 0.98 -pow 1 -c 0.5 \| nmrPipe -fn ZF -auto \| nmrPipe -fn FT -alt \| nmrPipe -fn PS -p0 0 -p1 0 -di \| nmrPipe -fn POLY -auto \| nmrPipe -fn TP \| nmrPipe -fn POLY -auto \ -verb -ov -out testB.ft2#nmrPipe -in test.ft2| pipe2xyz -nv -out hsqc2.nv -verb -ov</code></pre><p><strong>部分代码解释:</strong>COADD等同于co-addition of data,暂时没搞清楚其参数的含义</p><p><strong>4.对加减处理后的图谱标峰</strong></p><p>以IPAP谱为例,我们需要给add.ft2和sub.ft2的信号峰标上序号,以便与标准谱图进行比较。</p><p>在当前终端输入nmrDraw,回车,按第2部分打开并读取add.ft2。如果怀疑当前图谱遗漏了重要的谱峰信号,可以点击“Factor”右边的“-”,减小信号显示阈值,然后点击“Draw”;如果感觉谱图杂峰较多,可以点击“Factor”右边的“+”,增大信号显示阈值,然后点击“Draw”;如果需要进一步微调,还可以直接在First右边的空格中,输入自己认为合适的检测阈值,回车后点击“Draw”。接下来,右键单击“Peak”→“K) Peak Detection”</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig9.png" style="zoom: 30%;"></center><center><strong>图9</strong> 在nmrDraw中打开标峰窗口</center><p>此时便会弹出“Peak Detection”对话框,然后单击“Detect”按钮,标出图中所有峰的序号,之后更改峰序号表为“test_add.tab”,点击“Save”保存后即可退出。</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig10.png" style="zoom: 30%;"></center><center><strong>图10</strong> 在nmrDraw中标记所有显示的信号峰</center><p>用同样的方法,可以得到sub.ft2的峰序号表“test_sub.tab”,之后就可以比照标准图谱,进行峰的指认。</p><p><strong>5.峰的指认</strong></p><p>为完成峰的指认,通常需要准备一张已经标好信号峰与其归属残基的标准图谱。此处以泛素蛋白为例,其标准图谱的归属保存于wtUb_ass.tab,放置在与add.ft2和sub.ft2所处的文件夹下。我们需要在终端输入命令:</p><pre><code class="lang-bash">ipap.tcl -inName1 test_add.tab -specName1 add.ft2 -assName wtUb_ass.tab -single</code></pre><p>这样就可以开始对add.ft2的指认,此时会跳出如下窗口:</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig11.png" style="zoom: 30%;"></center><center><strong>图11</strong> 按正确格式运行ipap.tcl的结果</center><p>可以看到指认界面由若干部分组成:指认表(第一列为标准图谱中残基氨基酸代号和在多肽中的序号,第二列为测定图谱的序号,点击Next和Prev会跳转到上一个标准图谱序号对应的位置),指认图谱(含标准图谱和测定图谱的序号,红色方框为当前标准图谱序号对应的位置,绿色方框为测定图谱中指认的对应峰的位置)</p><p>由于指认图谱只显示一小部分,因此可以调节x轴和y轴的比例尺,使谱图显示得更为完整。例如输入以下命令并执行:</p><pre><code class="lang-bash">ipap.tcl -inName1 test_add.tab -specName1 add.ft2 -assName wtUb_ass.tab -single -xv 1 -yv 3</code></pre><p>此时会跳出如下窗口:</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig12.png" style="zoom: 30%;"></center><center><strong>图12</strong> 在ipap.tcl运行命令中加入-xv和-yv选项的结果</center><p>根据周围几个残基位移的大小,我们可以挪移标准图谱,使其与测定图谱对齐,例如输入以下命令并执行:</p><pre><code class="lang-bash">ipap.tcl -inName1 test_add.tab -specName1 add.ft2 -assName wtUb_ass.tab -single -xOff -0.025 -yOff 0.8</code></pre><p>此时会跳出如下窗口:</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig13.png" style="zoom: 30%;"></center><center><strong>图13</strong> 在ipap.tcl运行命令中加入-xOff和-yOff选项的结果</center><p>可以看到红色方框与绿色方框已经对准,此时点击指认表的“Next”,查看其余残基归属是否正确,如果某个残基缺乏归属,便不会出现对应的绿框,如下图所示</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig14.png" style="zoom: 30%;"></center><center><strong>图14</strong> 残基与实验信号峰缺乏对应时的界面</center><p>此时点击(你认为正确的归属位置对应的)灰色方框(如上图大红框所示),就可以将标准谱图的峰归属到测定谱图中“正确”的位置上,相应的,灰色方框就会变成绿色方框,代表红色小方框对应的残基标准位置,在实验谱图中对应于绿色小方框的位置</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig15.png" style="zoom: 30%;"></center><center><strong>图15</strong> 残基与实验信号峰存在对应时的界面</center><p>确认所有峰归属到正确位置上后(当然,有些标准图谱的峰在测定图谱中没有出现,这样的峰可以跳过),点击指认表的按钮“Save”,弹出保存窗口,重命名归属结果为sum.add_ass.tab,点击“Save”保存,之后即可退出指认窗口。用同样的方法,指认sub.ft2,将归属结果保存于sum.sub_ass.tab。</p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig16.png" style="zoom: 30%;"></center><center><strong>图16</strong> 保存归属结果时弹出的窗口</center><p><strong>后记:</strong>之前听老师讲解ipap.tcl的使用,突然发现只需输入如下命令,便能实现在同一界面下,同时归属IPAP拆分的两张谱。此时,标准图谱的峰最好位于高场分量与低场分量的正中间,便于归属时对照方便。要注意的是,使用该命令打开ipap.tcl后,保存时会提示先保存第一张谱的归属文件,然后提示保存第二张谱的归属文件,对于下列命令,意味着先保存add.ft2对应的归属文件,后保存sub.ft2对应的归属文件。</p><pre><code class="lang-bash">ipap.tcl -inName1 test_add.tab -specName1 add.ft2 -inName2 test_sub.tab -specName2 sub.ft2 -assName wtUb_ass.tab -single -xOff -0.025 -yOff 0.8</code></pre><p>此外,归属时有个小技巧:对于已经标记(显示为绿色方框)但是很明显对应错误的峰,可以用右键单击的方式将其取消,此时绿色方框会变成灰色方框,且原有的“等号+残基名”的标记将会消失,代表这个实验测出来的峰清空了原有归属。</p><p><strong>6. 峰归属的输出</strong><br>在当前终端输入以下命令并执行</p><pre><code class="lang-bash">grep -v one sum.add_ass.tab > temp2_add.tabgrep -v one sum.sub_ass.tab > temp2_sub.tabawk '{if (NR>4) print $23,$9 }' temp2_add.tab | sort -nk1 > add.hnawk '{if (NR>4) print $23,$9 }' temp2_sub.tab | sort -nk1 > sub.hn</code></pre><p>得到简化的峰归属表add.hn和sub.hn,它记录了每个残基的-NH-中N的化学位移</p><p><strong>7. RDC数据的整理</strong></p><p>(处理前一定要按照第1-6部分,将各向同性溶液的IPAP和各向异性溶液的IPAP处理好,得到对应的峰归属数据!)</p><p>用Execl打开各向同性溶液的add.hn和sub.hn,将add.hn或sub.hn的第一列,以及add.hn和sub.hn各自的第二列,复制到新的工作簿中,然后两两相减,存于第四列,得1_control.xlsx;对各向异性溶液的add.hn和sub.hn也作相似处理,得2_exp.xlsx。</p><p>然后将2_exp.xlsx的第四列与1_control.xlsx的第四列相减,得新列,存于delta.xlsx,取出残基名称列和新列,并将残基名称列的字母删去,另存为delta.hn。</p><p>注意:add.hn和sub.hn一定要保证峰与峰数据对齐,否则可能会多一行或少一行数据,导致部分数据无法正确相减!</p><h4 id="III-用RDC数据验证解析结构与实际结构的一致性"><a href="#III-用RDC数据验证解析结构与实际结构的一致性" class="headerlink" title="III. 用RDC数据验证解析结构与实际结构的一致性"></a>III. 用RDC数据验证解析结构与实际结构的一致性</h4><p>将RDC格式转换脚本rdc_format.sh、RDC数据delta.hn、用于RDC理论效应计算的泛素蛋白结构文件1ubq_ambH.pdb拷贝至原始图谱的根目录中,输入以下命令并运行,以生成RDC张量分析所需的输入文件:</p><pre><code class="lang-bash">./rdc_format.sh delta.hn > rdc.tbl</code></pre><p>再输入以下命令进行分析,并作出拟合曲线(需要预先安装Xplor-NIH):</p><pre><code class="lang-bash">calcTensor rdc.tbl 1ubq_ambH.pdb -plot</code></pre><p>结果如下图所示:</p><p><center class="half"><img src="/2022/11/17/RDC-data-processing-tutorial/RDC_doc_fig17.png" style="zoom: 40%;"></center></p><p><center><strong>图17</strong> calcTensor拟合结果</center><br>以下命令将给出具体数据,只要将终端输出的信息复制下来,即可用于后期拟合:</p><pre><code class="lang-bash">calcTensor rdc.tbl 1ubq_ambH.pdb -showRDCs</code></pre><h4 id="IV-补充:Xplor-NIH的安装"><a href="#IV-补充:Xplor-NIH的安装" class="headerlink" title="IV. 补充:Xplor-NIH的安装"></a>IV. 补充:Xplor-NIH的安装</h4><p><strong>直接解压缩法</strong></p><p>1.安装包下载:访问<a href="https://nmr.cit.nih.gov/xplor-nih/">Xplor-NIH</a>并登录,若为初次访问,按照其提示注册账号(邮箱最好采用学校邮箱)。登陆后下载最新版本的Xplor-NIH,它包括xplor-nih-VERSION-Linux_x86_64.tar.gz(x86_64版Linux的Xplor-NIH)和xplor-nih-VERSION-db.tar.gz(数据库和示例),VERSION为当前版本号。</p><p>2.解压缩:创建一个文件夹(如/home/(你的用户名)/Xplor/opt),并将xplor-nih-VERSION-Linux_x86_64.tar.gz和xplor-nih-VERSION-db.tar.gz移入该文件夹中,打开终端,输入:</p><pre><code class="lang-bash">tar -xzvf xplor-nih-VERSION-Linux_x86_64.tar.gztar -xzvf xplor-nih-VERSION-db.tar.gz</code></pre><p>这样就将Xplor-NIH解压到文件夹/home/(你的用户名)/Xplor/opt/xplor-nih-VERSION中</p><p>3.配置Xplor-NIH:输入以下命令</p><pre><code class="lang-bash">cd xplor-nih-VERSION./configure</code></pre><p>4.后续调整:以管理员(root)身份登录,在/home/(你的用户名)/Xplor/opt/xplor-nih-VERSION打开终端,输入./configure -symlinks DIR,回车。其中DIR为\$PATH所在位置,如\$HOME/bin或/usr/local/bin,可以用echo \$PATH获取。</p><p>5.测试Xplor运行情况:以普通用户身份登录,在/home/(你的用户名)/Xplor/opt/xplor-nih-VERSION打开终端,输入bin/testDist,回车。</p><p><strong>脚本安装法</strong></p><p>1.脚本下载:访问<a href="https://nmr.cit.nih.gov/xplor-nih/">Xplor-NIH</a>并登录,下载最新版本的installer-linux-VERSION.sh,并拷贝至/home/(你的用户名)/Xplor/opt</p><p>2.运行安装脚本:打开终端,输入chmod 777 installer-linux-VERSION.sh,回车(有GUI者,右键点属性→权限,全部修改为“允许读取、写入和执行”),然后输入./installer-linux-VERSION.sh,回车,等待压缩包全部下载并解压。</p><p>3.后续调整和测试:同“直接解压缩法”第4、5步。</p>]]></content>
<categories>
<category> 核磁共振波谱 </category>
</categories>
<tags>
<tag> 核磁共振波谱 </tag>
<tag> 残余偶极耦合 </tag>
<tag> RDC </tag>
<tag> NMRPipe </tag>
</tags>
</entry>
<entry>
<title>Hello World</title>
<link href="/2022/11/17/hello-world/"/>
<url>/2022/11/17/hello-world/</url>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p><h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><pre><code class="lang-bash">$ hexo new "My New Post"</code></pre><p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p><h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><pre><code class="lang-bash">$ hexo server</code></pre><p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p><h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><pre><code class="lang-bash">$ hexo generate</code></pre><p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p><h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><pre><code class="lang-bash">$ hexo deploy</code></pre><p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>]]></content>
</entry>
<entry>
<title>tags</title>
<link href="/tags/index.html"/>
<url>/tags/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>categories</title>
<link href="/categories/index.html"/>
<url>/categories/index.html</url>
<content type="html"><![CDATA[]]></content>
</entry>
<entry>
<title>404 Not Found</title>
<link href="//404.html"/>
<url>//404.html</url>
<content type="html"><![CDATA[<center><h3 style="font-size:32px;">非常抱歉,你似乎折跃到了错误的坐标</h3><div style="font-size:24px;">请检查链接书写是否正确,或<a href="/">点击此处</a>返回首页</div><del><font color="white">(指挥官,我们的情报又双叒叕出错了)</font></del></center>]]></content>
</entry>
</search>