SPONGE_PYPLUGIN
SPONGE的python接口
该插件将SPONGE视为一个python解释器,运行python脚本
依赖
该插件依赖于cupy。请自行安装好适配你CUDA版本的cupy。
为什么需要cupy?
SPONGE的GPU代码需要适配GPU的python端的库,许多库都能满足,如cupy、jax、torch以及mindspore。而cupy是上述里唯一一个支持“野”指针的库,也即cupy.cuda.UnownedMemory,使得它能直接调用SPONGE的内存地址作为自变量,而不需要显式地同步。另外cupy作为一个中介,它的数组也可以比较方便地转化为其他库的数组。
安装
安装方法:
1. pip 安装
使用命令
pip install sponge-pyplugin --root 安装地址的绝对路径
其中--root后请给出安装地址的绝对路径,使用绝对路径的原因是,pip会在临时文件夹中进行安装任务,如果你使用相对路径那么就会安装到临时文件夹的相对路径中,然后你就找不到它了。
2. 源码安装
前往gitee库下载解压或克隆源码
git clone https://gitee.com/gao_hyp_xyj_admin/sponge_pyplugin.git
打开下载并解压或克隆后的文件夹,在有setup.py的文件夹内呼出合适的shell终端,如windows下的powershell或linux下的shell
python setup.py install --root 安装地址的绝对路径
此处--root仍然需要给出安装路径的绝对路径,主要是为了与pip安装方式对齐。
使用
SPONGE命令
目前本插件适用的版本为:1.4a3,也即SPONGE的1.4版本第3内部测试版。
在SPONGE的mdin.txt文件夹中加入:
plugin = D:\SPONGE_pyplugin\sponge_pyplugin.so #你安装的本插件地址
py = D:\SPONGE_pyplugin\example.py #你需要使用的python脚本地址
此处的D:\SPONGE_pyplugin仅为示例,请修改为你对应的地址。
SPONGE获取python信息
SPONGE读取python信息使用的方式是读取函数名。
首先,SPONGE会直接逐行运行一遍该python脚本,由此可进行初始化。
然后,SPONGE会读取python脚本里的After_Initial()、Calculate_Force()和Mdout_Print(),分别在其他模块初始完毕、力计算和打印信息的时候调用。例如下面是一个简单的Example.py
def Mdout_Print():
print("Hellow SPONGE World!")
python获取SPONGE信息
python由模块Sponge获取SPONGE信息。模块Sponge是SPONGE作为解释器时的内置模块,在外部用python调用是没有的。
Sponge模块内包含四个子模块controller(程序控制)、cv_controller(CV定义)、md_info(MD信息)、mol_map(分子周期性映射)。这4个子模块的定义与C++版本的定义相同。可以使用help()寻求帮助。
import Sponge
help(Sponge.controller)
help(Sponge.cv_controller)
help(Sponge.md_info)
help(Sponge.mol_map)
简单例子
以下是一个简单的steer MD的例子,对第一个原子的y方向加上一个力。
import Sponge
my_force_factor = 1
if Sponge.controller.Command_Exist("my_force_factor"):
my_force_factor = float(Sponge.controller.Command("my_force_factor"))
Sponge.controller.Step_Print_Initial("My_Force_Potential", "%2f")
def Calculate_Force():
Sponge.md_info.frc[0][1] += my_force_factor
def Mdout_Print():
Sponge.controller.Step_Print("My_Force_Potential", -my_force_factor * Sponge.md_info.crd[0][1])
Metadata
Release files for sponge-pyplugin 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sponge_pyplugin-0.1.8.tar.gz | 53.7 kB | Without provenance | Details for sponge_pyplugin-0.1.8.tar.gz |
Release files / sponge_pyplugin-0.1.8.tar.gz
| Download URL | sponge_pyplugin-0.1.8.tar.gz |
|---|---|
| Size | 53.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf1521f0df8871f3fb9cb596a403f8d4514f963cbe49de001d8b03adec67ce85
|
|
BLAKE2b-256 checksum How to use checksums |
b2339b61b2f43741138da281af478236c8ce83fc7627cc6432717e1ad4eabc14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Security for sponge-pyplugin 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.