Skip to main content

CyFES:GPU加速高性能数据透视工具

Hex.pm Hex.pm Hex.pm Hex.pm Hex.pm

介绍

这是一个使用Cython+CUDA+Python编写的高性能FES计算软件,可以用于加速数据透视的计算:

$$ F_{avg}(x)=-kT\log\left(\frac{\sum_{j=1}^Ne^{\frac{V_j}{kT}}e^{-\frac{(x-n_j)^2}{2\sigma^2}}}{N\Pi_i\sqrt{2\pi}\sigma_i}\right)-F_{min} $$

$$ V(x)=w\sum_t\prod_ie^{-\frac{(x_i-\mu_t)^2}{2\sigma^2}} $$

$$ F(x)=-V-F_{min} $$

$$ V_g(x)=\frac{w'}{\sqrt{N}}\sum_i^NV(x_i)e^{-\frac{(x_i-x)^2}{2\sigma'^2}} $$

安装

pip安装

本项目可以直接使用pip进行安装:

$ python3 -m pip install cyfes --user --upgrade -i https://pypi.org/simple

源码安装

首先将本仓库clone到本地:

$ git clone https://gitee.com/dechin/cy-fes.git && cd cy-fes/

然后直接运行setup.py进行安装:

$ python3 -m pip install .

安装测试

在本仓库的test路径下存放了一个测试用例,用于测试cyfes是否安装成功。用户可以直接简单的运行:

$ python3 tests/test_path_fes.py 
[0.00902854 0.         0.09338432 0.02065182]
[0.03961432 0.         0.01514649 0.02259541]
[0.00129778 0.         0.02988457 0.0869869 ]
[0.01712827 0.01378975 0.         0.02229569]
[0.0114323  0.03356422 0.         0.0328276 ]

若输出为多个数组,则表示安装成功。也可以使用单元测试运行,但是这需要在本地先安装pytest:

$ python3 -m pip install pytest

然后直接在仓库的根目录下运行:

$ py.test
============================ test session starts =============================
platform linux -- Python 3.7.5, pytest-7.4.4, pluggy-1.2.0
rootdir: /home/cy-fes
collected 5 items                                                            

tests/test_path_fes.py .....                                           [100%]

============================= 5 passed in 14.23s =============================

没有报错,则表示安装成功。

使用方法

在安装成功后,可以直接在Python脚本中调用:

import numpy as np
from cyfes import PathFES
np.random.seed(0)

def test_path_fes():
    atoms = 4
    cvs = 10000
    crd = np.random.random((atoms, 3))
    cv = np.random.random((cvs, 3))
    bw = np.random.random(3)
    bias = np.random.random(cvs)-1

    fes = np.asarray(PathFES(crd, cv, bw, bias))
    print (fes)

if __name__ == '__main__':
    test_path_fes()

还可以使用命令行模式:

$ python3 -m cyfes --help
usage: __main__.py [-h] [-i I] [-ic IC] [-ib IB] [-s S] [-e E] [-g G] [-o O]
                   [-no_bias NO_BIAS] [-f32 F32] [-sigma SIGMA]
                   [-device DEVICE]

optional arguments:
  -h, --help        show this help message and exit
  -i I              Set the input record file path.
  -ic IC            Set the cv index of input record file. Default: 0,1,2
  -ib IB            Set the bias index of input record file. Default: 3
  -s S              CV length. Default: None
  -e E              Edge length. Default: 1.0
  -g G              Grid numbers. Default: 10,10,10
  -o O              Set the output FES file path.
  -no_bias NO_BIAS  Do not use the bias from input file. Default: false
  -f32 F32          Use float32. Default: false
  -sigma SIGMA      Sigma value when calculating FES. Default: 0.3
  -device DEVICE    Set the device ids separated with commas. Default: 0

假如我们有一个三维的CV,那么最简单的运行方式为:

$ python3 -m cyfes -i /home/Data/xyz_bias.txt -o ./work_dir/z.cub

那么最后产生的文件内容为:

$ head -n 10 work_dir/z.cub
Generated by CyFES
Total	1000	grids
1	21.6622	19.8498	42.3652
10	6.40465	0	0
10	0	7.02147	0
10	0	0	6.33118
1	1.000000	53.6854	54.9571	74.0211
450	450	450	450	450	450	
450	450	450	450	450	450	
450	450	70.0855	70.848	450	450	

该cube格式的文件可以在支持的软件(如VMD)中进行可视化操作。

已知问题

  1. 使用numpy==1.22.2的版本中会出现ImportError: numpy.core.multiarray failed to import问题。解决方案:升级numpy版本:python3 -m pip install numpy --upgrade。
  2. 执行python3 -m cyfes --help报错ModuleNotFoundError: No module named 'cyfes.wrapper',这是因为执行命令的目录下存在名为cyfes的文件夹,需要切换执行命令的位置。
  3. 使用cyfes出现Segmentation fault段错误问题,是因为找不到编译好的动态链接库文件,大概率是系统环境下权限不足,没有site路径的权限,可以使用如下脚本进行检查:
# check_dynamics.py
import os
import site
from pathlib import Path

site_path = Path(site.getsitepackages()[0])
site_file_path = site_path.parent.parent.parent / 'cyfes' / 'libcufes.so'
site_dynamics_path = str(site_file_path)

user_site_path = Path(site.USER_SITE)
user_file_path = user_site_path.parent.parent.parent / 'cyfes' / 'libcufes.so'
user_dynamics_path = str(user_file_path)

if not os.path.exists(site_dynamics_path) and not os.path.exists(user_dynamics_path):
    print ('Check dynamics complete, no libcufes.so file founded!')
else:
    print ('Installation of CyFES success!')

使用python3运行该脚本,即可判断动态链接库是否被正确安装。

Metadata

Release files for cyfes 4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cyfes 4.5
File Size Uploaded Provenance Actions
cyfes-4.5.tar.gz 354.4 kB Without provenance Details for cyfes-4.5.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for cyfes 4.5
File Actions
cyfes-4.5-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for cyfes-4.5-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
cyfes-4.5-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details for cyfes-4.5-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
cyfes-4.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details for cyfes-4.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cyfes-4.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details for cyfes-4.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Total release size: 7.2 MB

Release files / cyfes-4.5.tar.gz

Download URL cyfes-4.5.tar.gz
Size 354.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cfc2b040b18bfaaf2c890348c62ae75521a38d6858de9061434ec3f1708e7ebd
BLAKE2b-256 checksum
How to use checksums
c33f4c28db604c1c90f7db4d78af0bbce35fe2965072f3897afd9efd04331d2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.5

Release files / cyfes-4.5-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL cyfes-4.5-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8a6c6833c8f9839d4cdd8edadd8daa536b65d24244aa6156e71159e8da8dc2de
BLAKE2b-256 checksum
How to use checksums
9b62ac656be54c320b3d1cbdb738ecef36b6c2e723a2b585109da93432394bdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.5

Release files / cyfes-4.5-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL cyfes-4.5-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.7 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2cba765c922cbb47027a680779e810cc84092f2049738b3277b42530b48c57f8
BLAKE2b-256 checksum
How to use checksums
c99c079152089bbfb591d3fa5576eb0e3bec83a1b113baffb68a9a1966f18ca1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.5

Release files / cyfes-4.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyfes-4.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ae58302948bbf609416063793dc5c1574044d4f2dd85251cfbdfbc34167c5d2f
BLAKE2b-256 checksum
How to use checksums
d0d7f995960ec49f848397e7a01188ab17d8efdad3346a37760f26e3ddffeed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.5

Release files / cyfes-4.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cyfes-4.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6745e4f2bc7abaafff02243faf34c39fe9e418f3b5cb94f76d1856211261deaa
BLAKE2b-256 checksum
How to use checksums
d6a84f984a02cd7704752985bc3c0c413f95a690f9a08bf87db1045f1a6b704f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.5

Security for cyfes 4.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page