图神经网络与分子表征:番外——基组选择

news2024/9/21 2:36:40

学过高斯软件的人都知道,我们在撰写输入文件 gjf 时需要准备输入【泛函】和【基组】这两个关键词。

【泛函】敲定计算方法,【基组】则类似格点积分中的密度,与计算精度密切相关。

部分研究人员借用高斯中的一系列基组去包装输入几何信息(距离、角度和二面角),这样做一方面提高了GNN的可解释性,另一方面也实实在在的提高了模型精度。从 AI 角度看,embedding则可以看作是几何信息的升维。

具体来说:

  1. 如果模型输入仅有距离信息,则采用径向基函数去embedding。常用的有 Gaussian ,也有Bessel
  2. 如果模型输入含有距离和角度信息。在直角坐标系下,可以用 Gaussian 和 sin 函数组embedding。在球坐标系下,可以考虑 spherical Bessel functions and spherical harmonics 组合。其中 spherical harmonics 采用m=0的形式。
  3. 如果模型输入含有距离,角度和二面角信息,一般采用 spherical Bessel functions and spherical harmonics 组合。可能有其他的,但目前涉及二面角的模型较少,据我了解,Spherenet和ComENet均采用的是这种组合。

下面进行简要介绍:

Gaussian 系列基组

SchNet网络架构中使用的基组,是目前用途最广的基组之一。
我们借助 DIG 框架中 schnet 的实现,对其进行可视化:

from dig.threedgraph.method.schnet.schnet import *

import numpy as np
import math
import matplotlib.pyplot as plt

import torch


dist_test = torch.arange(0.01, 5.01, 0.01)
dist_emb = emb(num_gaussians=5)
y = dist_emb(dist_test)
y = y.T

for idx, y_plot in enumerate(y):
    x = [a_dist.detach().numpy() for a_dist in dist_test]
    y = [an_emb.detach().numpy() for an_emb in y_plot]

    plt.plot(x, y, label=f"Gaussian embedding {idx}")

plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.show()

结果如下图所示:
在这里插入图片描述
所谓,“对几何信息进行嵌入”,指,同一个距离信息对应x轴一个点。如果高斯基组有5,则,嵌入后,该距离信息就映射到了5个口袋里,获得一组长度为5的特征向量。

此处为了清晰的可视化,仅设置 num_gaussians=5 ,在实际应用中,这一数值往往设的很高。例如,原版的 schnet 将这一数值设为 300,在 DIG 版本中,这一数值是默认的 50,而在最新的 schnetpack 中,这一数值 降为了 20.

Bessel 系列基组

与高斯基组类似,Bessel 系列基组用于 embedding 距离信息,文献里用 spherical Bessel functions 表示。

其源头可以追溯到微分方程的求解,spherical Bessel functions 是作为一系列解中的径向部分存在,也常被称为 radical Bessel functions。

最早使用 Bessel functions 的(可能不严谨)GNN大概是 DimeNet。据 DimeNet 原文报道,使用 Bessel functions 会带来一定程度的精度提升。
我们借助 DIG 框架中 DimeNet 的实现,对其进行可视化:

from dig.threedgraph.method.spherenet.features import *

import numpy as np
import math
import matplotlib.pyplot as plt

import torch

dist_test = torch.arange(0.01, 5.01, 0.01)
dist_emb = dist_emb(num_radial=5)
y = dist_emb(dist_test)
y = y.T

for idx, y_plot in enumerate(y):
    x = [a_dist.detach().numpy() for a_dist in dist_test]
    y = [an_emb.detach().numpy() for an_emb in y_plot]

    plt.plot(x, y, label=f"radical_basis_{idx}")

plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.show()

结果如下图所示:
在这里插入图片描述

spherical harmonics 基组

spherical Bessel functions 和 spherical harmonics 不是一个基组。他俩分别对应方程特解中的径向和角度部分。
(下图为 ComENet 中的概述)在这里插入图片描述
spherical harmonics 基组常常在球极坐标系下,和 spherical Bessel functions 配套使用。
如果输入的几何信息仅有角度,没有二面角,我们将 spherical harmonics 中的 m 置零。
此时得到的是一系列二维的 embedding 矩阵。
我们借助 DIG 框架中 SphereNet 的实现,对其进行可视化(源码稍微改了改,此处仅是一些思路):

from dig.threedgraph.method.spherenet.features import *

import numpy as np
import math
import matplotlib.pyplot as plt

import torch

angle_emb = angle_emb(num_spherical=4, num_radial=4, cutoff=4)
rlist = np.arange(0, 4.01, 0.005)  # Angstroms
thetalist = np.radians(np.arange(0, 361, 0.5))  # Radians
rmesh, thetamesh = np.meshgrid(rlist, thetalist)  # Generate a mesh

n = 1
l = 1
fig = plt.figure()
info = angle_emb(torch.tensor(rlist), torch.tensor(thetalist))
info_0 = info[n, l]
info_0 = info_0.detach().numpy()

info_0 = info_0.reshape(len(rlist), len(thetalist))
info_0 = info_0.T
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(thetamesh, rmesh, info_0, 100, cmap='RdBu')
ax.set_rticks([])
ax.set_xticks([])
plt.savefig(f'./basis/n_{n}_l_{l}.png', dpi=400)

结果如下图所示:
请添加图片描述
我们可以得到一系列能够embedding角度和距离信息的函数。
下图是DimeNet原文中的图:
在这里插入图片描述
需要注意的是,DimeNet源码中对 l=0 的径向函数进行了修改,所以无法复现 Figure 2 第一行。

我们还可以借助 scipy 进行实现,例如,下面我们对角度部分 ( spherical harmonics )进行可视化(不涉及径向部分,径向部分在 scipy.special._spherical_bessel 里):

  1. 借用plotly实现可交互的可视化
import plotly.graph_objects as go
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from scipy.special import sph_harm

# from scipy.special._spherical_bessel import


# l, m = 3, 0

for l in range(0, 4):
    for m in range(-l, l+1):
        theta = np.linspace(0, np.pi, 100)
        phi = np.linspace(0, 2 * np.pi, 100)
        theta, phi = np.meshgrid(theta, phi)
        xyz = np.array([np.sin(theta) * np.sin(phi),
                        np.sin(theta) * np.cos(phi),
                        np.cos(theta)])

        Y = sph_harm(abs(m), l, phi, theta)

        if m < 0:
            Y = np.sqrt(2) * (-1) ** m * Y.imag
        elif m > 0:
            Y = np.sqrt(2) * (-1) ** m * Y.real
        Yx, Yy, Yz = np.abs(Y) * xyz

        fig = go.Figure(data=[go.Surface(x=Yx, y=Yy, z=Yz, surfacecolor=Y.real), ])

        fig.update_layout(title=f'Y_l_{l}_m_{m}', )

        fig.write_html(rf'./pics_html/Y_l_{l}_m_{m}.html')

  1. 借用matplotlib实现静态的可视化:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
# The following import configures Matplotlib for 3D plotting.
from mpl_toolkits.mplot3d import Axes3D
from scipy.special import sph_harm


# plt.rc('text', usetex=True)

# Grids of polar and azimuthal angles
theta = np.linspace(0, np.pi, 100)
phi = np.linspace(0, 2*np.pi, 100)
# Create a 2-D meshgrid of (theta, phi) angles.
theta, phi = np.meshgrid(theta, phi)
# Calculate the Cartesian coordinates of each point in the mesh.
xyz = np.array([np.sin(theta) * np.sin(phi),
                np.sin(theta) * np.cos(phi),
                np.cos(theta)])

def plot_Y(ax, el, m):
    """Plot the spherical harmonic of degree el and order m on Axes ax."""

    # NB In SciPy's sph_harm function the azimuthal coordinate, theta,
    # comes before the polar coordinate, phi.
    Y = sph_harm(abs(m), el, phi, theta)

    # Linear combination of Y_l,m and Y_l,-m to create the real form.
    if m < 0:
        Y = np.sqrt(2) * (-1)**m * Y.imag
    elif m > 0:
        Y = np.sqrt(2) * (-1)**m * Y.real
    Yx, Yy, Yz = np.abs(Y) * xyz

    # Colour the plotted surface according to the sign of Y.
    cmap = plt.cm.ScalarMappable(cmap='RdBu')
    cmap.set_clim(-0.5, 0.5)

    ax.plot_surface(Yx, Yy, Yz,
                    facecolors=cmap.to_rgba(Y.real),
                    rstride=2, cstride=2)

    # Draw a set of x, y, z axes for reference.
    ax_lim = 0.5
    ax.plot([-ax_lim, ax_lim], [0,0], [0,0], c='0.5', lw=1, zorder=10)
    ax.plot([0,0], [-ax_lim, ax_lim], [0,0], c='0.5', lw=1, zorder=10)
    ax.plot([0,0], [0,0], [-ax_lim, ax_lim], c='0.5', lw=1, zorder=10)
    # Set the Axes limits and title, turn off the Axes frame.
    # ax.set_title(r'$Y_{{{},{}}}$'.format(el, m))
    ax.set_title('Y_l_{}_m_{}'.format(el, m))
    ax_lim = 0.5
    ax.set_xlim(-ax_lim, ax_lim)
    ax.set_ylim(-ax_lim, ax_lim)
    ax.set_zlim(-ax_lim, ax_lim)
    ax.axis('off')

# fig = plt.figure(figsize=plt.figaspect(1.))

for l in range(0, 4):
    for m in range(-l, l+1):
        fig = plt.figure()
        ax = fig.add_subplot(projection='3d')
        plot_Y(ax, l, m)
        plt.savefig('./pics_png/Y_l_{}_m_{}.png'.format(l, m))

静态效果如下:
请添加图片描述
OK,至此,GNN中常用的基组(至少我所了解到的)介绍完了。
一般来说,仅涉及距离信息的架构常常采用 gaussian 基组。

如果要用 spherical harmonics 这种涉及角度的基组,一般需要将几何坐标转到球极坐标下,而这将导致网络适应等变架构时遇到困难。

当然,还有使用 tensor field 做基组的,这块我还了解的少,但看起来好像也是套的 spherical harmonics 。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/932307.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

快速安装Qt开发环境,克服在线安装慢等问题

自从Qt6之后&#xff0c;QtCreater的安装都需要注册账号&#xff0c;并且使用账号在线安装&#xff0c;继续使用官网的资源站下载的话&#xff0c;会特别的慢&#xff0c;以下是提高在线安装速度的做法。 官网下载很慢&#xff0c;快速安装的方式如下 1、winR,输入CMD&#xff…

深入分析负载均衡情景

本文出现的内核代码来自Linux5.4.28&#xff0c;为了减少篇幅&#xff0c;我们尽量不引用代码&#xff0c;如果有兴趣&#xff0c;读者可以配合代码阅读本文。 一、有几种负载均衡的方式&#xff1f; 整个Linux的负载均衡器有下面的几个类型&#xff1a; 实际上内核的负载均衡…

关于述职答辩的一点思考和总结

公众号&#xff1a;赵侠客 侠客说&#xff1a;优秀人才的四个特征&#xff1a;格局、思路、实干、写作 一、前言 1.1 述职答辩的重要性 公司都会有晋升通道&#xff0c;述职答辩是你想升职加薪除了跳槽以外的必由之路&#xff0c;其重要性对个人发展来说不言而喻&#xff0c…

python的文件操作

前言 打印内容到屏幕 最简单的输出方式是调用print函数&#xff0c;此函数会将你传递的表达式转化成字符串表达式&#xff0c;并将结果写道标准输出中。 读取键盘输入 python提供了两个raw_input和input内置函数从标准输入中读取一行文本&#xff0c;默认的标准输入是键盘。 …

7.接着跑一下triton官方教程

5.Model Ensemble 在此示例中&#xff0c;我们将探索使用模型集成来仅通过单个网络调用在服务器端执行多个模型。这样做的好处是减少了在客户端和服务器之间复制数据的次数&#xff0c;并消除了网络调用固有的一些延迟。 为了说明创建模型集成的过程&#xff0c;我们将重用第…

缺页异常与copy-on-write fork

缺页异常需要什么 当发生缺页异常时&#xff0c;内核需要以下信息才能响应这个异常&#xff1a; 出错的虚拟地址&#xff08;引发缺页异常的源&#xff09; 当一个用户程序触发了缺页异常&#xff0c;会切换到内核空间&#xff0c;将出错的地址放到STVAL寄存器中&#xff0c;…

JVM工具-1. jps:虚拟机进程状态工具

文章目录 1. jps介绍2. jps命令格式3. jps工具主要选项4. jps -q5. jps -m6. jps -l7. jps -v 1. jps介绍 jps(JVM Process Status Tool)&#xff1a;虚拟机进程状态工具&#xff0c;可以列出正在运行的虚拟机进程&#xff0c;并显示虚拟机执行主类&#xff08;Main Class&…

3.3.2:SUM作为一般函数及聚合函数的应用

【分享成果&#xff0c;随喜正能量】我们很多道友没受过什么苦&#xff0c;或受不了一句话、一点气&#xff0c;总想悠悠自在成佛。或是念上几十部经就想换取什么&#xff0c;法宝是无价的&#xff01;你拿有价来换&#xff0c;不但换不到&#xff0c;还丧失了功德。应当不退初…

springboot整合jdbctemplate教程

这篇文章介绍一下springboot项目整合jdbctemplate的步骤&#xff0c;以及通过jdbctemplate完成数据库的增删改查功能。 目录 第一步&#xff1a;准备数据库 第二步&#xff1a;创建springboot项目 1、创建一个springboot项目并命名为jdbctemplate 2、添加spring-jdbc和项目…

探讨uniapp的路由与页面生命周期问题

1 首先我们引入页面路由 2 页面生命周期函数 onLoad() {console.log(页面加载)},onShow() {console.log(页面显示)},onReady(){console.log(页面初次显示)},onHide() {console.log(页面隐藏)},onUnload() {console.log(页面卸载)},onBackPress(){console.log(页面返回)}3 页面…

一串神奇的字符,就能让ChatGPT在内的AI聊天机器人变得不正常

一组看似随机的字符被添加到对话提示的末尾&#xff0c;就会发现几乎任何聊天机器人都显露了邪恶本性。 卡内基梅隆大学计算机科学教授Zico Kolter和博士生Andy Zou的一份报告&#xff0c;揭示了当前主流的聊天机器人&#xff0c;特别是ChatGPT&#xff0c;以及Bard、Claude等…

python print ljust 文本对齐打印 对齐打印名册

背景 在python部分场景下&#xff0c;我们需要打印输出一些文本消息&#xff0c;但我们又无法预测可能的打印内容是什么。这种情况下&#xff0c;我们要对齐打印这些文本&#xff0c;是比较比较难以处理的。 例如下面是一列姓名&#xff0c;和对应的一列手机/电话号&#xff0…

自然对数底e的一些事

自然对数底e的一些事 走的人多了就成了路 中国清代数学家李善兰&#xff08;1811—1882&#xff09; 凡此变数中函彼变数者&#xff0c;则此为彼之函数 自然对数底也是使用习惯 &#x1f349; 李善兰把function翻译为函数&#xff0c;函就是包含&#xff0c;含有变量&#xff…

C# Winfrom通过COM接口访问和控制Excel应用程序,将Excel数据导入DataGridView

1.首先要创建xlsx文件 2.在Com中添加引用 3. 添加命名空间 using ApExcel Microsoft.Office.Interop.Excel; --这样起个名字方面后面写 4.样例 //点击操作excelDataTable dt new DataTable();string fileName "D:\desktop\tmp\test.xlsx";ApExcel.Application exA…

【学习FreeRTOS】第20章——FreeRTOS内存管理

1.FreeRTOS内存管理简介 在使用 FreeRTOS 创建任务、队列、信号量等对象的时&#xff0c;一般都提供了两种方法&#xff1a; 动态方法创建&#xff1a;自动地从FreeRTOS管理的内存堆中申请创建对象所需的内存&#xff0c;并且在对象删除后&#xff0c;可将这块内存释放回Free…

牛客练习赛 114

C.Kevin的七彩旗 思路&#xff1a;贪心和dp均可以解决。 贪心&#xff1a;我们可以发现&#xff0c;最终想要获得合法的序列&#xff0c;我们必须是通过把几段连续的序列拼凑起来&#xff0c;但序列之间可能有重合&#xff0c;因此我们就转化为了&#xff0c;记录每一段最大的…

IP编址数据转发(md版)

IP编址&数据转发 一、IP编址1.1、二进制、十进制和十六进制1.2、进制之间的转换1.3、IP编址1.4、子网掩码1.5、二进制和十进制转换1.6、IP地址分类1.7、IP地址类型1.8、地址规划 二、VLSM与CIDR2.1、有类IP编址的缺陷2.2、变长子网掩码 VLSM2.3、缺省情况下的掩码2.4、子网…

Redis使用

环境配置 代码实现 Java public CoursePublish getCoursePublishCache(Long courseId){//查询缓存Object jsonObj redisTemplate.opsForValue().get("course:" courseId);if(jsonObj!null){String jsonString jsonObj.toString();System.out.println("从缓…

Linux安装1Panel(官方)

项目简介安装命令 curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && sh quick_start.sh 访问地址 查看命令&#xff1a;1pctl user-info 常用命令 Usage:1pctl [COMMAND] [ARGS...]1pctl --helpCommands: status …

王道考研:特权指令、用户态与核心态、内核程序与应用程序;中断和异常;系统调用;宏内核与微内核;电脑开机全过程;虚拟机原理

一、操作系统的运行机制 kernel当中包含的是OS当中最核心的部分&#xff0c;像图形界面不是放在kernel当中的&#xff0c;离开图像界面OS仍然可以通过命令行来使用 CPU拿到一条指令就已经可以区分它是特权指令还是非特权指令了 操作系统根据PSW来判断当前正在运行的是用户程序…