2024年11月

技术背景

CudaSPONGE是基于CUDA C开发的一款纯GPU分子动力学模拟软件,具有模块化和高性能的特点。官方基本介绍内容如下:

分子动力学(Molecular Dynamics, MD)模拟是化学、物理学、生物学、材料科学和许多其他领域的有用工具。在过去 40 年中,人们开发了各种高效的计算算法和MD程序,用于研究日益复杂和大型系统的动力学,如RNA 聚合酶、细胞膜中的膜蛋白、SARS-CoV-2病毒等。然而,随着应用范围和规模的扩大,分子模拟软件需要更高的计算能力。缩小模拟与实验之间差距的最直接策略是利用更强大的计算硬件。例如,Shaw研究所专门设计了安东(Anton),可以对系统大小为几百万个原子的单结构域蛋白质进行毫秒级模拟。相比之下,使用图形处理单元(GPU)可能是大多数研究小组最经济实惠和最有前途的方法。从另一个方面看,许多先进的计算算法也已开发出来并得到广泛应用,从而延长了模拟时间尺度。特别是在过去几十年中,人们开发了许多增强型采样方法,以实现快速热力学和/或动力学计算。这些方法包括但不限于广泛使用的伞状采样、元动力学、加速MD、复制交换分子动力学(REMD)、并行回火、模拟回火、多正则模拟(特别是通过Wang-Landau算法实现)以及许多其他方法。

在过去的 15 年中,我们致力于开发面向复杂化学和生物系统的高效分子模拟方法,设计了一系列增强型采样方法,实现了构象和轨迹空间的快速采样,并实现了复杂系统热力学和动力学特性的快速计算。 最近,我们开发了一个名为 SPONGE的国产MD模拟软件包,它不仅实现了GPU加速的传统MD模拟,还实现了我们课题组提出的高效增强采样方法。 该软件包具有高度模块化的特点,可以轻松集成其他功能或算法,尤其是最新的深度学习潜力和算法。

安装介绍

首先进到
CudaSPONGE官网
,找到最新版本的软件包下载到本地目录,主要依赖于
nvcc
进行编译构建。解包之后可以看到这样的目录:

$ ll
total 220
drwxrwxrwx 1 root root  4096 Sep 11 08:19 ./
drwxrwxrwx 1 root root  4096 Sep 11 08:19 ../
drwxrwxrwx 1 root root  4096 Sep 11 08:19 Lennard_Jones_force/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 MD_core/
-rwxrwxrwx 1 root root  3072 Jan  1  2024 Makefile*
drwxrwxrwx 1 root root  4096 Sep 11 08:19 No_PBC/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 PME_force/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 SITS/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 angle/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 barostats/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 bias/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 bond/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 cmap/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 collective_variable/
-rwxrwxrwx 1 root root  8311 Jan  1  2024 common.cu*
-rwxrwxrwx 1 root root 58097 Jan  1  2024 common.cuh*
drwxrwxrwx 1 root root  4096 Sep 11 08:19 constrain/
-rwxrwxrwx 1 root root 41504 Jan  1  2024 control.cu*
-rwxrwxrwx 1 root root  9465 Jan  1  2024 control.cuh*
drwxrwxrwx 1 root root  4096 Sep 11 08:19 covid-tip4p/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 dihedral/
-rwxrwxrwx 1 root root 34743 Jan  1  2024 jit.cuh*
-rwxrwxrwx 1 root root 32719 Jan  1  2024 main.cu*
-rwxrwxrwx 1 root root  2011 Jan  1  2024 main.cuh*
-rwxrwxrwx 1 root root  3408 Jan  1  2024 main_ti.cu*
-rwxrwxrwx 1 root root   489 Jan  1  2024 main_ti.cuh*
-rwxrwxrwx 1 root root   492 Jan  1  2024 mdin.txt*
drwxrwxrwx 1 root root  4096 Sep 11 08:19 nb14/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 neighbor_list/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 plugin/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 restrain/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 thermostats/
drwxrwxrwx 1 root root  4096 Sep 11 08:19 virtual_atoms/
-rwxrwxrwx 1 root root 11843 Jan  1  2024 vs_project_generator.bat*
drwxrwxrwx 1 root root  4096 Sep 11 08:19 wall/

然后可以在这个路径下直接执行:

$ make

过程中大致输出为:

编译输出
$ make
/bin/sh: bc: command not found
/bin/sh: bc: command not found
analyzing dependency of PME_force/cross_PME.cu to PME_force/cross_PME.d
analyzing dependency of PME_force/PME_force.cu to PME_force/PME_force.d
analyzing dependency of Lennard_Jones_force/LJ_soft_core.cu to Lennard_Jones_force/LJ_soft_core.d
analyzing dependency of neighbor_list/neighbor_list.cu to neighbor_list/neighbor_list.d
analyzing dependency of MD_core/MD_core.cu to MD_core/MD_core.d
analyzing dependency of control.cu to control.d
analyzing dependency of common.cu to common.d
analyzing dependency of main_ti.cu to main_ti.d
analyzing dependency of plugin/plugin.cu to plugin/plugin.d
analyzing dependency of wall/soft_wall.cu to wall/soft_wall.d
analyzing dependency of wall/hard_wall.cu to wall/hard_wall.d
analyzing dependency of bias/Meta1D.cu to bias/Meta1D.d
analyzing dependency of bias/steer.cu to bias/steer.d
analyzing dependency of bias/restrain_cv.cu to bias/restrain_cv.d
analyzing dependency of collective_variable/combine.cu to collective_variable/combine.d
analyzing dependency of collective_variable/tabulated.cu to collective_variable/tabulated.d
analyzing dependency of collective_variable/RMSD.cu to collective_variable/RMSD.d
analyzing dependency of collective_variable/simple_cv.cu to collective_variable/simple_cv.d
analyzing dependency of collective_variable/collective_variable.cu to collective_variable/collective_variable.d
analyzing dependency of SITS/SITS.cu to SITS/SITS.d
analyzing dependency of virtual_atoms/virtual_atoms.cu to virtual_atoms/virtual_atoms.d
analyzing dependency of constrain/SHAKE.cu to constrain/SHAKE.d
analyzing dependency of constrain/SETTLE.cu to constrain/SETTLE.d
analyzing dependency of constrain/simple_constrain.cu to constrain/simple_constrain.d
analyzing dependency of constrain/constrain.cu to constrain/constrain.d
analyzing dependency of restrain/restrain.cu to restrain/restrain.d
analyzing dependency of barostats/andersen_barostat.cu to barostats/andersen_barostat.d
analyzing dependency of barostats/Berendsen_barostat.cu to barostats/Berendsen_barostat.d
analyzing dependency of barostats/MC_barostat.cu to barostats/MC_barostat.d
analyzing dependency of thermostats/nose_hoover_chain.cu to thermostats/nose_hoover_chain.d
analyzing dependency of thermostats/Berendsen_thermostat.cu to thermostats/Berendsen_thermostat.d
analyzing dependency of thermostats/Andersen_thermostat.cu to thermostats/Andersen_thermostat.d
analyzing dependency of thermostats/Middle_Langevin_MD.cu to thermostats/Middle_Langevin_MD.d
analyzing dependency of thermostats/Langevin_MD.cu to thermostats/Langevin_MD.d
analyzing dependency of Lennard_Jones_force/pairwise_force.cu to Lennard_Jones_force/pairwise_force.d
analyzing dependency of Lennard_Jones_force/solvent_LJ.cu to Lennard_Jones_force/solvent_LJ.d
analyzing dependency of Lennard_Jones_force/Lennard_Jones_force.cu to Lennard_Jones_force/Lennard_Jones_force.d
analyzing dependency of No_PBC/Lennard_Jones_force_No_PBC.cu to No_PBC/Lennard_Jones_force_No_PBC.d
analyzing dependency of No_PBC/generalized_Born.cu to No_PBC/generalized_Born.d
analyzing dependency of No_PBC/Coulomb_Force_No_PBC.cu to No_PBC/Coulomb_Force_No_PBC.d
analyzing dependency of nb14/nb14.cu to nb14/nb14.d
analyzing dependency of cmap/cmap.cu to cmap/cmap.d
analyzing dependency of dihedral/improper_dihedral.cu to dihedral/improper_dihedral.d
analyzing dependency of dihedral/dihedral.cu to dihedral/dihedral.d
analyzing dependency of angle/Urey_Bradley_force.cu to angle/Urey_Bradley_force.d
analyzing dependency of angle/angle.cu to angle/angle.d
analyzing dependency of bond/listed_forces.cu to bond/listed_forces.d
analyzing dependency of bond/bond_soft.cu to bond/bond_soft.d
analyzing dependency of bond/bond.cu to bond/bond.d
analyzing dependency of main.cu to main.d
/bin/sh: bc: command not found
/bin/sh: bc: command not found
nvcc -o main.o -c main.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o common.o -c common.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o control.o -c control.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o MD_core/MD_core.o -c MD_core/MD_core.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/config.h:27:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config.h:23,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:24,
                 from MD_core/MD_core.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/cpp_dialect.h:131:13: warning: Thrust requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define THRUST_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      THRUST_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                           
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_arch.cuh:36:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/detail/device_synchronize.cuh:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/util.h:36,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/for_each.h:35,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/adl/for_each.h:42,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/for_each.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/for_each.h:277,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.h:104,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/transform.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/transform.h:721,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.inl:31,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.h:87,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/reduce.inl:28,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/reduce.h:781,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.h:61,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/find.inl:25,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/find.h:381,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.h:152,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:1358,
                 from MD_core/MD_core.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_cpp_dialect.cuh:142:13: warning: CUB requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define CUB_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      CUB_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                        
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/config.h:27:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config.h:23,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:24,
                 from MD_core/MD_core.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/cpp_dialect.h:131:13: warning: Thrust requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define THRUST_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      THRUST_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                           
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_arch.cuh:36:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/detail/device_synchronize.cuh:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/util.h:36,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/for_each.h:35,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/adl/for_each.h:42,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/for_each.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/for_each.h:277,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.h:104,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/transform.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/transform.h:721,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.inl:31,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.h:87,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/reduce.inl:28,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/reduce.h:781,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.h:61,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/find.inl:25,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/find.h:381,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.h:152,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:1358,
                 from MD_core/MD_core.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_cpp_dialect.cuh:142:13: warning: CUB requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define CUB_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      CUB_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                        
nvcc -o bond/bond.o -c bond/bond.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o bond/bond_soft.o -c bond/bond_soft.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o bond/listed_forces.o -c bond/listed_forces.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o angle/angle.o -c angle/angle.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o angle/Urey_Bradley_force.o -c angle/Urey_Bradley_force.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o dihedral/dihedral.o -c dihedral/dihedral.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o dihedral/improper_dihedral.o -c dihedral/improper_dihedral.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o cmap/cmap.o -c cmap/cmap.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o nb14/nb14.o -c nb14/nb14.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o neighbor_list/neighbor_list.o -c neighbor_list/neighbor_list.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/config.h:27:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config.h:23,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:24,
                 from neighbor_list/neighbor_list.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/cpp_dialect.h:131:13: warning: Thrust requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define THRUST_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      THRUST_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                           
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_arch.cuh:36:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/detail/device_synchronize.cuh:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/util.h:36,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/for_each.h:35,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/adl/for_each.h:42,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/for_each.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/for_each.h:277,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.h:104,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/transform.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/transform.h:721,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.inl:31,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.h:87,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/reduce.inl:28,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/reduce.h:781,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.h:61,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/find.inl:25,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/find.h:381,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.h:152,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:1358,
                 from neighbor_list/neighbor_list.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_cpp_dialect.cuh:142:13: warning: CUB requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define CUB_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      CUB_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                        
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/config.h:27:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config.h:23,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:24,
                 from neighbor_list/neighbor_list.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/config/cpp_dialect.h:131:13: warning: Thrust requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define THRUST_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      THRUST_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                           
In file included from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_arch.cuh:36:0,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/cub/detail/device_synchronize.cuh:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/util.h:36,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/for_each.h:35,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/adl/for_each.h:42,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/for_each.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/for_each.h:277,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/transform.h:104,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/transform.inl:27,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/transform.h:721,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.inl:31,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/reduce_by_key.h:87,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/reduce.inl:28,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/reduce.h:781,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.inl:19,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/find.h:61,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/find.inl:25,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/find.h:381,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sort.h:152,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/sort.inl:26,
                 from /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/sort.h:1358,
                 from neighbor_list/neighbor_list.cu:2:
/usr/local/cuda/bin/../targets/x86_64-linux/include/cub/util_cpp_dialect.cuh:142:13: warning: CUB requires at least C++14. C++11 is deprecated but still supported. C++11 support will be removed in a future release. Define CUB_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
      CUB_COMPILER_DEPRECATION_SOFT(C++14, C++11);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                        
nvcc -o No_PBC/Coulomb_Force_No_PBC.o -c No_PBC/Coulomb_Force_No_PBC.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o No_PBC/generalized_Born.o -c No_PBC/generalized_Born.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o No_PBC/Lennard_Jones_force_No_PBC.o -c No_PBC/Lennard_Jones_force_No_PBC.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o Lennard_Jones_force/Lennard_Jones_force.o -c Lennard_Jones_force/Lennard_Jones_force.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o Lennard_Jones_force/solvent_LJ.o -c Lennard_Jones_force/solvent_LJ.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o Lennard_Jones_force/LJ_soft_core.o -c Lennard_Jones_force/LJ_soft_core.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o Lennard_Jones_force/pairwise_force.o -c Lennard_Jones_force/pairwise_force.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o PME_force/PME_force.o -c PME_force/PME_force.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o thermostats/Langevin_MD.o -c thermostats/Langevin_MD.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o thermostats/Middle_Langevin_MD.o -c thermostats/Middle_Langevin_MD.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o thermostats/Andersen_thermostat.o -c thermostats/Andersen_thermostat.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o thermostats/Berendsen_thermostat.o -c thermostats/Berendsen_thermostat.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o thermostats/nose_hoover_chain.o -c thermostats/nose_hoover_chain.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o barostats/MC_barostat.o -c barostats/MC_barostat.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o barostats/Berendsen_barostat.o -c barostats/Berendsen_barostat.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o barostats/andersen_barostat.o -c barostats/andersen_barostat.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o restrain/restrain.o -c restrain/restrain.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o constrain/constrain.o -c constrain/constrain.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o constrain/simple_constrain.o -c constrain/simple_constrain.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o constrain/SETTLE.o -c constrain/SETTLE.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o constrain/SHAKE.o -c constrain/SHAKE.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o virtual_atoms/virtual_atoms.o -c virtual_atoms/virtual_atoms.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o SITS/SITS.o -c SITS/SITS.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o collective_variable/collective_variable.o -c collective_variable/collective_variable.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o collective_variable/simple_cv.o -c collective_variable/simple_cv.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o collective_variable/RMSD.o -c collective_variable/RMSD.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o collective_variable/tabulated.o -c collective_variable/tabulated.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o collective_variable/combine.o -c collective_variable/combine.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o bias/restrain_cv.o -c bias/restrain_cv.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o bias/steer.o -c bias/steer.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o bias/Meta1D.o -c bias/Meta1D.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o wall/hard_wall.o -c wall/hard_wall.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o wall/soft_wall.o -c wall/soft_wall.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o plugin/plugin.o -c plugin/plugin.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
sed -i 's/\r//' mdin.txt
sed -i 's/\r//' covid-tip4p/*
nvcc -o SPONGE  main.o common.o control.o MD_core/MD_core.o bond/bond.o bond/bond_soft.o bond/listed_forces.o angle/angle.o angle/Urey_Bradley_force.o dihedral/dihedral.o dihedral/improper_dihedral.o cmap/cmap.o nb14/nb14.o neighbor_list/neighbor_list.o No_PBC/Coulomb_Force_No_PBC.o No_PBC/generalized_Born.o No_PBC/Lennard_Jones_force_No_PBC.o Lennard_Jones_force/Lennard_Jones_force.o Lennard_Jones_force/solvent_LJ.o Lennard_Jones_force/LJ_soft_core.o Lennard_Jones_force/pairwise_force.o PME_force/PME_force.o thermostats/Langevin_MD.o thermostats/Middle_Langevin_MD.o thermostats/Andersen_thermostat.o thermostats/Berendsen_thermostat.o thermostats/nose_hoover_chain.o barostats/MC_barostat.o barostats/Berendsen_barostat.o barostats/andersen_barostat.o restrain/restrain.o constrain/constrain.o constrain/simple_constrain.o constrain/SETTLE.o constrain/SHAKE.o virtual_atoms/virtual_atoms.o SITS/SITS.o collective_variable/collective_variable.o collective_variable/simple_cv.o collective_variable/RMSD.o collective_variable/tabulated.o collective_variable/combine.o bias/restrain_cv.o bias/steer.o bias/Meta1D.o wall/hard_wall.o wall/soft_wall.o plugin/plugin.o -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o main_ti.o -c main_ti.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o PME_force/cross_PME.o -c PME_force/cross_PME.cu -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50
nvcc -o SPONGE_TI  main_ti.o common.o control.o MD_core/MD_core.o neighbor_list/neighbor_list.o Lennard_Jones_force/LJ_soft_core.o PME_force/PME_force.o PME_force/cross_PME.o -rdc=true -lcudadevrt -lcuda -lcudart -lcufft -lnvrtc --use_fast_math -O4 -ldl -std=c++11 -arch=sm_50 -DCUDA_ARCH_BIN=50

即可完成
CudaSPONGE
的编译构建,在当前路径下生成一个
SPONGE
可执行文件:

$ ll | grep SPONGE
-rwxr-xr-x 1 root root 32455648 Nov 27 01:44 SPONGE*
-rwxr-xr-x 1 root root  7482232 Nov 27 01:44 SPONGE_TI*

预处理

为了使得工作空间更加分明,这里我建议先创建一个独立的工作区:

$ mkdir work_dir

准备一个待模拟的体系,例如我们这里使用一个简单的pdb纯蛋白体系:

REMARK   Generated By Xponge (Molecule)
ATOM      1    N ALA     1      -0.095 -11.436  -0.780
ATOM      2   CA ALA     1      -0.171 -10.015  -0.507
ATOM      3   CB ALA     1       1.201  -9.359  -0.628
ATOM      4    C ALA     1      -1.107  -9.319  -1.485
ATOM      5    O ALA     1      -1.682  -9.960  -2.362
ATOM      6    N ARG     2      -1.303  -8.037  -1.397
ATOM      7   CA ARG     2      -2.194  -7.375  -2.328
ATOM      8   CB ARG     2      -3.606  -7.943  -2.235
ATOM      9   CG ARG     2      -4.510  -7.221  -3.228
ATOM     10   CD ARG     2      -5.923  -7.789  -3.136
ATOM     11   NE ARG     2      -6.831  -7.111  -4.087
ATOM     12   CZ ARG     2      -8.119  -7.421  -4.205
ATOM     13  NH1 ARG     2      -8.686  -8.371  -3.468
ATOM     14  NH2 ARG     2      -8.844  -6.747  -5.093
ATOM     15    C ARG     2      -2.273  -5.882  -2.042
ATOM     16    O ARG     2      -1.630  -5.388  -1.119
ATOM     17    N ALA     3      -3.027  -5.119  -2.777
ATOM     18   CA ALA     3      -3.103  -3.697  -2.505
ATOM     19   CB ALA     3      -1.731  -3.041  -2.625
ATOM     20    C ALA     3      -4.039  -3.001  -3.483
ATOM     21    O ALA     3      -4.614  -3.643  -4.359
ATOM     22    N ALA     4      -4.235  -1.719  -3.394
ATOM     23   CA ALA     4      -5.126  -1.057  -4.325
ATOM     24   CB ALA     4      -6.538  -1.625  -4.233
ATOM     25    C ALA     4      -5.205   0.436  -4.039
ATOM     26    O ALA     4      -4.561   0.930  -3.116
ATOM     27  OXT ALA     4      -5.915   1.166  -4.728
TER

因为pdb格式经常会面临文件不完整的问题,所以需要使用Xponge进行预处理,安装方法如下:

$ python3 -m pip install xponge --upgrade

文件处理的流程,这里用
ipython
的交互结果做一个简单的演示:

In [1]: import Xponge

In [2]: import Xponge.forcefield.amber.ff14sb # 导入力场
Reference for ff14SB:
  James A. Maier, Carmenza Martinez, Koushik Kasavajhala, Lauren Wickstrom, Kevin E. Hauser, and Carlos Simmerling
    ff14SB: Improving the accuracy of protein side chain and backbone parameters from ff99SB
    Journal of Chemical Theory and Computation 2015 11 (8), 3696-3713
    DOI: 10.1021/acs.jctc.5b00255


In [3]: C = Xponge.load_pdb("case1.pdb", ignore_hydrogen=False, ignore_unknown_name=True) # 加载pdb文件

In [4]: C.add_missing_atoms() # 补齐氢原子和其他丢失的residue atom

In [5]: Xponge.save_pdb(C, "case1_fix.pdb") # 将新的体系保存到pdb文件中

In [7]: !mkdir protein

In [8]: Xponge.save_sponge_input(C, "protein/case1") # 保存SPONGE模拟所需参数文件
Reference for Xponge:
  Xia, Y., Gao, Y. Q.
    Xponge: A Python package to perform pre- and post-processing of molecular simulations
    Journal of Open Source Software, 2022 7(77) 4467
    DOI: 10.21105/joss.04467

Out[8]: Entity of Molecule: case1

In [10]: !ls -l protein/
total 32
-rwxr-xr-x 1 root root 1361 Nov 27 01:34 case1_LJ.txt
-rwxr-xr-x 1 root root 2717 Nov 27 01:34 case1_angle.txt
-rwxr-xr-x 1 root root  185 Nov 27 01:34 case1_atom_name.txt
-rwxr-xr-x 1 root root  153 Nov 27 01:34 case1_atom_type_name.txt
-rwxr-xr-x 1 root root 1437 Nov 27 01:34 case1_bond.txt
-rwxr-xr-x 1 root root  544 Nov 27 01:34 case1_charge.txt
-rwxr-xr-x 1 root root 1639 Nov 27 01:34 case1_coordinate.txt
-rwxr-xr-x 1 root root 4298 Nov 27 01:34 case1_dihedral.txt
-rwxr-xr-x 1 root root  977 Nov 27 01:34 case1_exclude.txt
-rwxr-xr-x 1 root root  371 Nov 27 01:34 case1_mass.txt
-rwxr-xr-x 1 root root 3197 Nov 27 01:34 case1_nb14.txt
-rwxr-xr-x 1 root root   16 Nov 27 01:34 case1_residue.txt
-rwxr-xr-x 1 root root   20 Nov 27 01:34 case1_resname.txt

这里除了补齐丢失的原子之外,还涉及到
CudaSPONGE
输入文件的问题,因此用Xponge来处理会相对便捷一些。到这里,就完成了
CudaSPONGE
分子模拟的预处理。

能量极小化

对于不同的模拟方法,我们需要给SPONGE输入不同的配置文件,例如能量最小化的一个配置文件的简单形式为
minimize.txt

case1 Minimization

mode = Minimization 
minimization_dynamic_dt 1
default_in_file_prefix = protein/case1

pbc=0 
cutoff=999

dt = 1e-02
step_limit = 5000
write_information_interval = 50

rst = restart

coordinate_in_file =  protein/case1_coordinate.txt

在这个配置文件下,我们执行能量极小化的
mode
,参数文件保存在
protein/
目录下,并以
case1
开头。而模拟系统的笛卡尔坐标,由文件
protein/case1_coordinate.txt
给出。这个设置方便的地方在于,因为我们设置了
restart
参数,所以模拟结束之后会在当前路径下保存一个
restart_coordinate.txt
重启文件,所以下一次启动模拟的时候,只要把启动文件指向到这个restart坐标文件就可以了。配置好参数之后,运行的指令为:

$ ../SPONGE -mdin minimize.txt

就可以获得相应的输出。

其他类型模拟

最常见的就是控温,那么主要就是设定
mode=NVT
,例如这是一个简单的
nvt.txt
,对应SPONGE的mdin输入文件:

case1 MD simulation

mode = NVT
default_in_file_prefix = protein/case1

pbc=0 
cutoff=999

dt = 1e-3
step_limit = 50000
write_information_interval = 5000

thermostat = middle_langevin
middle_langevin_gamma = 10

rst = nvt_restart

coordinate_in_file =  restart_coordinate.txt

这里起始坐标直接使用能量极小化之后的结果,并将NVT的最终坐标保存到
nvt_restart_coordinate.txt
文件中。其他如NPT模式的配置,可以参考
这篇博客
中的介绍。

增强采样

在CudaSPONGE v1.4的版本中,增强采样方法的定义形式如下
meta.txt

case1 MD simulation

mode = NVT
default_in_file_prefix = protein/case1

pbc=0 
cutoff=999

dt = 1e-3
step_limit = 50000
write_information_interval = 5000

target_temperature = 300.0
thermostat = middle_langevin
middle_langevin_gamma = 10

rst = meta_restart

coordinate_in_file =  nvt_restart_coordinate.txt
cv_in_file = cv.txt

dont_check_input = 1

其中额外包含了一个CV的定义文件
cv.txt
,内容如下:

print
{
    CV = torsion
}

torsion
{
   CV_type = dihedral
   atom = 1 3 12 13
}

meta1d
{
    CV = torsion
    dCV = 0.06
    CV_minimal = -3.1416
    CV_maximum = 3.1416
    CV_period = 6.2832
    welltemp_factor = 50
    height = 1
    sigma = 0.3
}

一样的运行方法,可以看到输出结果如下:

$ ../SPONGE -mdin meta.txt 
SPONGE Version:
    v1.4 2024-01-01

Sub-package:
    SPONGE, for normal molecular dynamics simulations

Citation:
    Huang, Y. - P., Xia, Y., Yang, L., Wei, J., Yang, Y.I.and Gao, Y.Q. (2022), SPONGE: A GPU - Accelerated Molecular Dynamics Package with Enhanced Sampling and AI - Driven Algorithms.Chin.J.Chem., 40 : 160 - 168. https ://doi.org/10.1002/cjoc.202100456


MD TASK NAME:
    case1 MD simulation

START INITIALIZING CONTROLLER
    Start initializing CUDA
        Compiled by CUDA 11.6
        1 device found:
            Device 0:
                Name: NVIDIA GeForce RTX 3080 Ti Laptop GPU
                Memory: 16.0 GB
                Compute Capability: 86
        Set Device 0
    End initializing CUDA
    structure last modify date is 20231219
END INITIALIZING CONTROLLER

START INITIALIZING CV CONTROLLER:
    1 CV defined
    0 cv virtual atoms
END INITIALIZING CV CONTROLLER

START INITIALIZING MD CORE:
    Mode set to NVT
    dt set to 0.001000 ps
    Start reading mass:
    End reading mass

    Start reading charge:
    End reading charge

    Start reading coordinate_in_file:
        atom_numbers is 57
        system start_time is 50.000000
        box_length is
            x: 999.000000
            y: 999.000000
            z: 999.000000
    End reading coordinate_in_file

    Velocity is set to zero as default
    skin set to 2.00 Angstrom
    cutoff set to 999.00 Angstrom
    Start reading excluded list:
        excluded list total length is 290
    End reading excluded list

    Start reading residue list:
        residue_numbers is 4
    End reading residue list

    structure last modify date is 20211105
END INITIALIZING MD CORE

START INITIALIZING MIDDLE LANGEVIN DYNAMICS:
    atom_numbers is 57
    target temperature is 300.00 K
    friction coefficient is 10.00 ps^-1
    random seed is 1476805525
    structure last modify date is 20210826
END INITIALIZING MIDDLE LANGEVIN DYNAMICS

START INITIALIZING LENNADR JONES INFORMATION:
    atom_numbers is 57
    atom_LJ_type_number is 8
    structure last modify date is 20220601
END INITIALIZING LENNADR JONES INFORMATION

START INITIALIZING COULOMB INFORMATION:
    structure last modify date is 20220603
END INITIALIZING COULOMB INFORMATION

START INITIALIZING NB14 (nb14_in_file):
    non-bond 14 numbers is 135
    structure last modify date is 20211222
END INITIALIZING NB14

LISTED FORCES IS NOT INITIALIZED

START INITIALIZING BOND (bond_in_file):
    bond_numbers is 56
    structure last modify date is 20210830
END INITIALIZING BOND

START INITIALIZING BOND SOFT:
END INITIALIZING SOFT BOND

START INITIALIZING ANGLE (angle_in_file):
    angle_numbers is 99
    structure last modify date is 20210830
END INITIALIZING ANGLE

UREY BRADLEY IS NOT INITIALIZED

START INITIALIZING DIHEDRAL (dihedral_in_file):
    dihedral_numbers is 137
    structure last modify date is 20210830
END INITIALIZING DIHEDRAL

IMPROPER DIHEDRAL IS NOT INITIALIZED

START INITIALIZING CMAP:
CMAP IS NOT INITIALIZED

START INITIALIZING HARD WALL:
END INITIALIZING HARD WALL

SOFT WALLS ARE NOT INITIALIZED

RESTRAIN IS NOT INITIALIZED

START INITIALIZING RESTRAIN CV:
    0 CV(s) found for restrain
RESTRAIN CV IS NOT INITIALIZED

START INITIALIZING STEER CV:
    0 CV(s) found for steer
STEER CV IS NOT INITIALIZED

START INITIALIZING META1D:
    1 CV(s) found for meta1d
        CV 0: torsion
        reading 4 atom(s) for torsion
            atom 0: 1
            atom 1: 3
            atom 2: 12
            atom 3: 13
            type of 'torsion' is 'dihedral'
    reading 1 CV_period(s) for meta1d
        CV_period 0: 6.283200
    reading 1 CV_minimal(s) for meta1d
        CV_minimal 0: -3.141600
    reading 1 CV_maximum(s) for meta1d
        CV_maximum 0: 3.141600
    reading 1 dCV(s) for meta1d
        dCV 0: 0.060000
    reading 1 height(s) for meta1d
        height 0: 1.000000
    reading 1 sigma(s) for meta1d
        sigma 0: 0.300000
    reading 1 welltemp_factor(s) for meta1d
        welltemp_factor 0: 50.000000
    Potential update interval is set to write_information_interval by default
    potential output file: meta1d_potential.txt
END INITIALIZING META1D

VIRTUAL ATOM IS NOT INITIALIZED

START INITIALIZING CV PRINTER:
    1 CV(s) found for print
        CV 0: torsion
            type of 'torsion' is 'dihedral'
END INITIALIZING CV PRINTER

------------------------------------------------------------------------------------------------------------
           step =            5000,            time =          55.000,     temperature =          391.02, 
      potential =         -187.55,              LJ =           -6.25,         Coulomb =         -308.21, 
        nb14_LJ =            7.49,         nb14_EE =           23.77,            bond =           19.29, 
          angle =           31.16,        dihedral =           43.88,          meta1d =            1.32, 
        torsion =         -2.3809, 
------------------------------------------------------------------------------------------------------------
           step =           10000,            time =          60.000,     temperature =          298.28, 
      potential =         -183.35,              LJ =           -5.40,         Coulomb =         -316.07, 
        nb14_LJ =            9.65,         nb14_EE =           29.10,            bond =           19.95, 
          angle =           33.31,        dihedral =           43.66,          meta1d =            2.45, 
        torsion =         -2.5452, 
------------------------------------------------------------------------------------------------------------
           step =           15000,            time =          65.000,     temperature =          433.99, 
      potential =         -188.78,              LJ =           -4.70,         Coulomb =         -316.29, 
        nb14_LJ =            8.71,         nb14_EE =           23.72,            bond =           21.29, 
          angle =           26.82,        dihedral =           47.90,          meta1d =            3.77, 
        torsion =         -2.4958, 
------------------------------------------------------------------------------------------------------------
           step =           20000,            time =          70.000,     temperature =          249.71, 
      potential =         -183.19,              LJ =           -5.34,         Coulomb =         -329.13, 
        nb14_LJ =            9.73,         nb14_EE =           31.84,            bond =           22.68, 
          angle =           34.74,        dihedral =           50.28,          meta1d =            2.01, 
        torsion =         -1.9129, 
------------------------------------------------------------------------------------------------------------
           step =           25000,            time =          75.000,     temperature =          355.19, 
      potential =         -190.72,              LJ =           -7.80,         Coulomb =         -314.26, 
        nb14_LJ =            8.21,         nb14_EE =           23.10,            bond =           19.06, 
          angle =           29.59,        dihedral =           48.39,          meta1d =            3.01, 
        torsion =         -1.8429, 
------------------------------------------------------------------------------------------------------------
           step =           30000,            time =          80.000,     temperature =          407.06, 
      potential =         -181.22,              LJ =            0.79,         Coulomb =         -293.82, 
        nb14_LJ =            6.62,         nb14_EE =            5.15,            bond =           24.57, 
          angle =           32.20,        dihedral =           41.94,          meta1d =            1.32, 
        torsion =          0.4504, 
------------------------------------------------------------------------------------------------------------
           step =           35000,            time =          85.000,     temperature =          203.30, 
      potential =         -179.47,              LJ =            0.97,         Coulomb =         -298.49, 
        nb14_LJ =            8.28,         nb14_EE =            4.97,            bond =           27.75, 
          angle =           39.17,        dihedral =           35.27,          meta1d =            2.61, 
        torsion =          0.4398, 
------------------------------------------------------------------------------------------------------------
           step =           40000,            time =          90.000,     temperature =          310.20, 
      potential =         -190.12,              LJ =           -3.52,         Coulomb =         -296.07, 
        nb14_LJ =            9.64,         nb14_EE =           13.64,            bond =           16.37, 
          angle =           28.68,        dihedral =           39.10,          meta1d =            2.03, 
        torsion =         -0.0447, 
------------------------------------------------------------------------------------------------------------
           step =           45000,            time =          95.000,     temperature =          408.99, 
      potential =         -190.56,              LJ =           -2.71,         Coulomb =         -296.55, 
        nb14_LJ =            8.19,         nb14_EE =           10.34,            bond =           19.28, 
          angle =           30.85,        dihedral =           36.49,          meta1d =            3.57, 
        torsion =          0.0334, 
------------------------------------------------------------------------------------------------------------
           step =           50000,            time =         100.000,     temperature =          462.33, 
      potential =         -189.09,              LJ =           -0.75,         Coulomb =         -293.79, 
        nb14_LJ =            9.71,         nb14_EE =            6.49,            bond =           18.99, 
          angle =           27.54,        dihedral =           38.08,          meta1d =            4.63, 
        torsion =         -0.0077, 
------------------------------------------------------------------------------------------------------------
Core Run Wall Time: 13.704983 seconds
Core Run Speed: 315.220093 ns/day
End Pause

总结概要

本文简单介绍了一下CudaSPONGE高性能分子动力学模拟软件,其基于原生的CUDA C开发,具有极高的模拟效率。结合前处理工具Xponge用于生成和处理输入文件,可以很好的兼容目前常用的很多力场形式。

版权声明

本文首发链接为:
https://www.cnblogs.com/dechinphy/p/cudasponge.html

作者ID:DechinPhy

更多原著文章:
https://www.cnblogs.com/dechinphy/

请博主喝咖啡:
https://www.cnblogs.com/dechinphy/gallery/image/379634.html

参考链接

  1. https://www.cnblogs.com/bgalang/p/18316362

介绍

JxAudio
是一个基于.net core的音频管理系统,支持音乐的播放、上传、下载、删除等功能。 兼容Subsonic协议,可以使用Subsonic客户端进行访问。 支持Windows、Linux、MacOS等操作系统。目前只提供Docker部署方式,其他方式须自行编译安装包,Windows和Linux提供ffmpeg二进制文件,MacOS需要自行安装ffmpeg。

特点

  • 支持插件功能,可以自定义插件进行扩展

  • 支持直连网盘,可以直接播放网盘音乐

  • 目前官方支持Alist网盘直接播放

  • 可自行扩展后台页面,对音乐进行自定义管理

优势

其最大的优势就是支持插件,可以利用插件直连网盘或者其他存储位置,目前已支持AList,可以通过AList扩展各种网盘。这样我们就可以将其安装在openwrt或者armbian上面,由于这些位置常常没有足够大的硬盘,无法作为存储位置,所以我们的常用音乐管理软件如Navidrome可能无法在上面安装。但是我们往往有一个比较大又用不到那么大的网盘,如阿里云盘或者OneDrive这种,我们完全可以将音乐放置在网盘上,然后通过AList挂载,然后使用JxAudio挂载AList网盘的形式直接播放阿里云盘或者OneDrive上的内容。这种方式由于是直接获取原生播放路径,所以不需要将AList通过WebDav或者其他方式模拟挂载为本地硬盘,相对而言效率会更高,并且出错的概率会更小。

同时,由于目前的AList和本地播放都是使用插件进行处理的,所以可以制作更多的插件,来满足更多的需求,比如直接挂载OneDrive,绕过AList,或者在线修改MusicTag,这都是可以做到的。

部署

目前JxAudio推荐通过Docker的方式进行部署,目前j4587698/jxaudio支持x64、arm64、armv7三种架构。

docker run -d -p 4587:4587 -v /path/to/config:/app/config -v /path/to/log:/app/log --name jxaudio j4587698/jxaudio

其中4587为程序默认监听端口。

/app/config为配置文件所在目录,里面存放着安装配置以及歌曲封面的缓存,同时如果使用Sqlite作为数据库,则默认的数据库也会建立在这个目录下。

/app/log是程序的日志目录。

同时JxAudio支持Windows、Linux、Macos,目前需要自行编译安装包,其中windows x86 x64,Linux x86 x64 armv7 arm64的ffmpeg已经内置,可以直接使用,macos或linux musl等系统或架构需要自行安装ffmpeg。

开源地址以及协议

目前项目使用GPL3.0开源在Github:https://github.com/j4587698/JxAudio

欢迎大家star

客户端

目前官方客户端还在开发中,由于兼容Subsonic协议,所以目前可以使用"音流"作为客户端进行使用,服务器类型选择Subsonic即可。

大家好,我是汤师爷~

让我们深入探讨库存概念模型设计,这是实现库存管理系统的基础,也是确保库存数据准确性和一致性的关键。

库存的数据模型设计

如图所示,展示了库存概念模型设计。通过合理的概念模型设计,我们可以更好地支持库存管理的各项业务需求。

仓库层

仓库层是实际存放和管理商品库存的层次,执行具体的仓储作业任务。它包括企业自营仓库、第三方物流仓库、线下门店的库存。

通常,仓库层通过仓库管理系统(WMS)、门店POS系统或ERP系统管理仓库库存的进销存,所有的库存变动均通过出入库单据完成。

仓库层的核心概念模型为仓库库存,由一系列核心属性描述:

  • 货主
    :货物所有权的拥有者,用于区分多货主环境下的库存归属。
  • 仓库/门店
    :存储货物的逻辑单元,与物理仓库不同,一个物理仓库可能包含多个逻辑仓库单元。
  • SKU
    :库存管理的最小单位,标识具体的商品及其规格。
  • 批号
    :用于区分每一批投料生产的产品,便于质量追溯。例如,在医药行业中,批号能用于快速定位并召回特定批次的产品。
  • 生产日期
    :标记成品生产的日期和时间,常用于管理保质期商品的库存。
  • 库存状态
    :描述库存在不同业务场景下的状态,例如:
    • 可用
      :可立即销售的库存。
    • 冻结
      :因质检或特殊业务需要,暂不可用的库存。
    • 在途
      :已从仓库发货,但尚未到达目的地的库存。
    • 不良品/废品
      :因质量问题,暂不具备使用价值的库存。
  • 库位
    :指仓库中实际存放商品的具体位置,是库存管理的最小粒度。

调度层

在库存管理体系中,调度层是连接仓库层与业务层的关键桥梁,负责汇总各仓库和门店的库存状态,以支持全局库存的统一调配。

通过将调度层与仓库层分离,企业能够简化对库存细节的管理(如批号、库位等),专注于全局库存的汇总与调配。

这种解耦的设计提高了库存管理的灵活性和效率,特别适合全渠道业务场景中的动态库存分配。调度层的核心概念模型为实物库存,核心属性包括:

  • 仓库/门店
    :库存所在的逻辑单元。
  • SKU
    :具体商品及其规格。
  • 库存状态
    :包括可用、不可用、在途等状态,描述库存在不同业务场景下的状态。
  • 在途库存
    :指供应商已发货但尚未到库的库存。在一些场景中,为了避免缺货,企业可能将这部分库存计入可用实物库存中。例如,在促销期间,将部分在途库存提前上架商城销售,确保用户下单时有足够库存。
  • 账面实物库存
    :门店/仓库中实际存放的库存,只要是未出库的都算在账面库存中。
  • 不可用实物库存
    :指因质量检测、冻结或其他原因暂时不可销售的库存。例如,某批次商品因质检未通过,被标记为不可用库存。
  • 预占实物库存
    :订单提交并分仓成功后,对应仓库的库存会被预占,防止其他订单重复占用。订单取消或发货后,库存状态会相应调整。
  • 可用实物库存
    :可用实物库存是账面实物库存减去预占实物库存、不可用实物库存的剩余部分。可用实物库存 = 账面实物库存 - 预占实物库存 - 不可用实物库存。

销售层

销售层是三层库存架构中的核心环节,负责管理各个销售渠道的库存分配与同步。通过精确的库存计算和灵活的分配策略,为销售渠道提供实时、可靠的库存服务,防止超卖,保障库存利用最大化。

1、销售库存的核心属性

销售层的核心概念模型为销售库存,包含以下核心属性:

  • 销售渠道
    :包括自营商城、门店线下渠道,以及第三方平台(如天猫、京东、美团、饿了么)等。
  • 销售店铺
    :指销售的具体店铺或门店。
  • 发货方式
    :库存支持的履约方式,如快递、同城配送、自提等。
  • 配送区域
    :因仓库覆盖范围不同,SKU支持的配送区域也有所限制。
  • 销售可用库存:
    按照仓库/门店的供货关系和渠道分配策略,计算出汇总的可销售库存数量。订单支付成功后,会扣减销售可用库存。
  • 预售库存:
    在商品未到货时开启预售模式,提前售卖的库存。实物库存与预售库存是隔离开的,当实物到货后,预售库存统一转化为实物库存进行履约。
  • 预占库存:
    订单已提交但未支付之前,为给顾客预留商品,会先预占商品库存,待支付以后再删除预占库存,扣减可用库存。若长时间未支付,则会取消订单,释放预占库存。
  • 活动库存:
    针对某些SKU做促销活动时,例如特价、秒杀活动,需要设置活动库存,可以从正常库存中预留部分库存,活动开始后释放预留库存。
  • 可售库存:
    可售库存 = 预售库存 + 销售可用库存 - 预占库存 - 活动库存

2、活动库存

在促销活动中,如何高效管理活动库存,避免库存超卖或分配不足?活动库存的处理是促销活动能否顺利进行的关键。以下是2种常见的处理方式:

1)共享库存

共享库存指活动库存与普通商品库存共用,无论通过活动售出还是普通售出,均从同一个库存池中扣减。这种方式通常用于满减、满赠、满折等促销活动。

  • 优点
    :库存管理简单,适用于无需精确分配活动库存的场景。
  • 缺点
    :在普通商品销量过高时,可能影响活动商品的库存供给。

2)独占库存

独占库存指活动库存与普通商品库存隔离。活动开始前,普通库存会转移一部分到活动库存。活动结束后,未售完的活动库存会返还普通库存。这种方式常用于秒杀、特价活动。

  • 优点
    :精确控制活动库存,避免活动库存不足的情况出现。
  • 缺点
    :管理较复杂,活动前需转换库存,结束后需归还库存,需要额外逻辑支持。

库存管理场景示例

本节将介绍几个典型的库存管理场景。这些场景涵盖了多仓供货、单仓给多店供货、门店全渠道共享以及组合商品等常见业务模式。通过这些具体案例,可以更好地理解库存模型的实际应用。

多仓供货场景

多仓供货指将多个实体仓库或门店的库存整合,统一供应线上渠道。这种模式通过整合库存、就近发货,提升配送效率、降低成本。

在本案例中,门店A和门店B被设置为天猫旗舰店的供货来源。门店A拥有100件iPhone 14库存,而门店B则持有50件iPhone 14库存。通过库存整合,两家门店的库存被汇总为线上可售库存,总量为150件。

天猫旗舰店仅支持快递配送,系统设置了快递发货的最大分配比例为80%。

根据这一规则,天猫渠道的最终库存为:150件 × 80% = 120件。剩余30件库存被保留在门店,可以用于线下销售或其他特殊场景。

单仓给多店供货场景

单仓给多店供货场景是指一个仓库为多个销售渠道提供库存支持。

商家在电商平台运营中,以一个中央电商仓作为核心仓储与配送中心,为多个线上店铺提供库存支持。

以电商仓储备的100件iPhone 14为例,可采用按比例分配策略:假设京东渠道销量较好,分配60%库存;天猫渠道分配40%,各自独立扣减。

这种策略的主要缺点是可能造成库存浪费。由于难以精准预测各渠道的销量,往往会出现某些渠道库存过剩而其他渠道库存不足的情况,导致错失销售机会,造成潜在损失。

另一种策略是库存共享,即多个渠道共用同一库存池。例如,100件iPhone 14在各渠道初始库存均显示为100件,当某一渠道售出后,系统自动同步更新所有渠道的库存数量。

但这种方案也存在缺陷:由于多渠道库存同步存在时间延迟,可能导致超卖问题。

为此,可以设置安全库存作为缓冲。例如,实际库存100件时,仅在各渠道上架90件,预留10件作为安全库存。

在单仓给多店供货场景中,商家需要在按比例分配、库存共享两种策略之间寻求平衡。通过引入安全库存机制,既可以提高库存利用率,又能有效防范同步延迟带来的超卖风险。

门店全渠道库存共享场景

在新零售模式下,如何实现线上线下渠道的深度融合,最大化门店库存的利用率?门店全渠道库存共享模式,通过整合线上线下的库存资源,为企业提供了一盘货的解决方案。

受益于微信生态和小程序电商的高速发展,越来越多的门店开始打造线上小程序。小程序可以理解为门店的“线上货架”,通过小程序将门店商品展示给消费者。消费者无需到店即可浏览、下单,门店导购也可以通过小程序向会员推荐商品,实现高效转化。

门店A持有 100 份草莓蛋糕,通过全渠道库存共享模式,将库存整合为“一盘货”,同时在美团外卖、小程序、门店线下渠道进行售卖。

组合商品的库存处理场景

在新零售业务中,组合商品是通过将多个单品捆绑为套餐形式销售的一种方式,例如下午茶套餐、七夕美妆组合等。

这种商品形式能够提升消费者的购买意愿,但也对库存管理提出了更高要求。

组合商品的库存管理主要在调度层完成,调度层根据子商品的库存数量和组合比例,计算组合商品的虚拟库存。例如,商品A库存为150件,商品B库存为200件,组合关系为 1 件商品A + 2 件商品B。组合商品C的虚拟库存计算为:MIN(150 / 1, 200 / 2) = 100 件。

当消费者下单购买组合商品C时,系统会根据组合商品的标识,锁定1件商品A和2件商品B的库存,防止其他订单重复使用。订单支付完成后,正式扣减子商品A和B的库存数量。

本文已收录于,我的技术网站:
tangshiye.cn
里面有,算法Leetcode详解,面试八股文、BAT面试真题、简历模版、架构设计,等经验分享。

2024年11月1日,GodoOS荣耀地入选了GVP——Gitee最有价值开源项目。在GVP平台收录的418个杰出项目中,GodoOS作为唯一一款用GO语言开发的、维护中的跨平台webOS的桌面应用,历经近三年的精心雕琢,从最初的简单设计,逐步进化到如今的成熟与易用。GodoOS在如此众多优秀项目中,GodoOS脱颖而出,荣获这一殊荣。

Gitee,这一由开源中国(OSChina)倾力打造的基于Git的代码托管服务,已然跃升为国内首屈一指的代码托管平台。Gitee的GVP(Gitee Most Valuable Project)——Gitee最有价值开源项目计划,旨在挖掘并展示那些在技术创新和可持续发展方面表现卓越的开源项目。

简介

GodoOS是一款专为内网办公打造的高效操作系统,集成了word、excel、ppt、pdf、聊天、白板、思维导图等多个办公系统工具。它支持AI创作、知识库和原生文件存储,为用户提供了一站式的办公解决方案。平台界面仿照Windows风格,操作简便,同时保持低资源消耗和高性能运行。无需注册即可自动连接内网用户,实现即时通讯和文件共享。其应用商店灵活且高配置,支持无限扩展,满足用户的多样化需求。

特性

  • 无需联网使用,全开源
    :无需网络连接即可使用,所有代码均开源,便于二次开发和定制。
  • AI创作功能强大
    :内置先进的AI创作引擎,支持文本生成、图片处理、代码编写等多种创作任务。用户无需依赖云端服务,即可在本地完成高质量的创作工作。AI功能的本地化集成,确保了创作的安全性和隐私性。
  • 零配置,无需注册,下载即用
    :简化使用流程,用户无需进行复杂配置或注册,下载后即可立即使用。
  • 零污染,无插件依赖
    :纯净无广告,不依赖任何第三方插件,确保系统稳定性和安全性。
  • 精小,打包后仅70M
    :尽管体积小,但包含了完整的办公套件,满足日常办公需求。
  • 可无限扩展,支持自定义应用
    :提供丰富的API和文档,支持用户自定义应用,满足个性化需求。
  • golang开发后端,低资源消耗和高性能
    :采用Go语言开发后端,确保系统资源消耗低且运行高效。
  • 支持多平台
    :兼容Windows、Linux、MacOS等主流操作系统,实现跨平台使用。
  • 完善的应用商店体系
    :提供简单易用的应用商店配置,方便用户和开发者开发复杂应用。

欢迎加入

每一个开源项目的成功都离不开背后一群人的支持。GodoOS未来将继续不断更新和完善,诚邀感兴趣的朋友加入我们的项目。无论您是开发者、设计师、文档撰写者,还是对此方向有兴趣的朋友,我们都热烈欢迎您的加入。

致谢

衷心感谢Gitee对我们的认可和支持,感谢所有参与GodoOS开发和维护的团队成员,以及所有支持和关注我们的用户。您的信任和支持是我们不断前行的动力。我们期待与更多志同道合的朋友携手共进,共同推动GodoOS的发展和创新。

在我们日常工作中,可能会经常使用MySQL数据库,因为它是开源免费的,而且性能还不错。

在国内的很多公司中,经常被使用。

但我们在MySQL使用过程中,也非常容易踩坑,不信继续往下看。

今天这篇文章重点跟大家一起聊一聊使用 MySQL 的15个坑,希望对你会有所帮助。

1查询不加where条件

有些小伙伴,希望在代码中,一次性把表中的所有数据都查出来,然后在内存中处理业务逻辑,认为代码性能更好。

反例:

SELECT * FROM users;

在查询数据的时候不加where条件。

这种情况下数据量小还好。

但如果数据量很大,每个业务操作,都需要查出表中的所有数据,可能会导致程序出现OOM问题。

如果数据太多,处理速度也会集聚下降。

正例:

SELECT * FROM users WHERE code = '1001';

使用具体的where查询条件,比如code字段,先过滤数据,再做处理。

2 没有使用索引

有时候,我们的程序,在刚上线的时候,数据比较少,没有加索引,问题不大。

但随着用户量越来越多,表中数据在呈指数级的增加。

突然有一天发现,查询数据变慢了。

例如:

SELECT * FROM orders WHERE customer_id = 123;

我们可以给customer_id字段加个索引:

CREATE INDEX idx_customer ON orders(customer_id);

这能大大提升速度!

3 不处理 NULL 值

问题描述:统计时忘了 NULL 的影响,以为结果准确,结果却大相径庭。

反例:

SELECT COUNT(name) FROM users;  

这些只能统计name字段非NULL的数量。

其实,没有统计完全。

如果想统计所有的记录行数,我们可以使用
COUNT(*)

正例:

SELECT COUNT(*) FROM users;

这样就能统计所有行数。

4 数据类型选错

有些小伙伴,在创建表时,随意使用 VARCHAR(255),会导致性能低下,还浪费存储。

反例:

CREATE TABLE products (
    id INT,
    status VARCHAR(255) 
);

这种情况的性能不佳。

我们可以将status字段该成tinyint类型:

CREATE TABLE products (
    id INT,
    status tinyint(1) DEFAULT '0' COMMENT '状态 1:有效 0:无效'
);

更节省空间。

5 深分页问题

我们在日常工作中,经常会遇到需要分页查询数据的场景。

我们一般会使用limit关键字。

例如:

SELECT * FROM users LIMIT 0,10;  

如果数据多的时候,第一页、第二页、第三页可能查询性能还OK。

但如果查询到第10万页,可能查询性能,就会变得非常差。

这就出现了深分页问题。

如何解决深分页问题?

5.1 记录上一次的id

我们现在的主要问题是,在分页的查询过程中,假如要查询第10万页的数据,要先扫描第9万9999页的数据。

但如果我们把上一次查询的位置记录下,后面再查询下一页的时候,就可以直接从之前的位置开始,往后查询。

例如下面这样的:

select id,name where order 
where id>1000000 limit 100000,10

上一次查询获取到的最大的id是1000000,那么本次查询直接从1000000的下一个位置开始查询。

这样就可以不用查询前面的数据,提升不少的查询效率。

但这套方案有两个需要注意的地方:

需要记录上一次的查询出的id,适合上一页或下一页的场景,不适合随机查询到某一页。
需要id字段是自增的。

5.2 使用子查询

先用子查询查询出符合条件的主键,再用主键id做条件查出所有字段。

select * from order where id in (
 select id from (
  select id from order where time>'2024-08-11' limit 100000, 10
 ) t
)

这样子查询中,可以走覆盖索引。

我们之前的SQL,查询10条数据,但需要回表100010次。

实际上,我们只需要查询10条数据,也就是我们只需要10次回表其实就够了。

通过子查询的方式,能够减少回表的次数。

因此,我们可以通过减少回表次数来优化深分页的问题。

5.3 使用inner join关联查询

根据子查询类似:

select * from order o1
inner join (
   select id from order 
    where create_time>'2024-08-11' 
    limit 100000,10
) as o2 on o1.id=o2.id;

在inner join子语句中,也是先通过查询条件和分页条件过滤数据,返回id。

然后再通过id做关联查询。

可以减少回表的次数,从而提升查询速度。

6 没有用explain分析查询

有些现在sql语句,查询慢,却不去分析执行计划,结果就只能盲目优化。

正例:

EXPLAIN SELECT * FROM users WHERE email = 'test@example.com';

EXPLAIN 会告诉你查询是怎么执行的,帮助你找到瓶颈。

如果大家想进一步了解explain关键字,可以看看我的另一篇文章《
SQL性能优化神器
》,里面有非常详细的介绍。

7 字符集设置不当

有些小伙伴,喜欢将MySQL的字符集设置成utf8。

我几年之前也喜欢这干。

但后面出现问题了,比如在用户评价输入框中,用户输入了表情符合,可能会直接导致程序保存。

字符集设置错误,也可能会导致汉字变乱码,用户体验直线下滑。

正例:

CREATE TABLE messages (
    id INT,
    content TEXT
) CHARACTER SET utf8mb4; 

建议大家在建表时,将字符集设置成使
utf8mb4
,它能够支持更多的字符,包括:常用中文汉字和一些表情符号。

8 SQL注入风险

用拼接 SQL 的方式,容易被 SQL 注入攻击,安全隐患大。

在一些自定义排序规则,使用order by 动态拼接用户选择的排序字段,或者排序方式,比如:升序或降序时,如果处理不好,就可能会出现SQL注入问题。

反例:

String query = "SELECT * FROM users WHERE email = '" + userInput + "';";

尽量少在sql中直接拼接字符串,而应该使用PreparedStatement预编译的方式。

正例:

PreparedStatement stmt = connection.prepareStatement("SELECT * FROM users WHERE email = ?");
stmt.setString(1, userInput);

在MyBatis中在使用$符号赋值时要注意,最好使用#符号赋值。

如果大家对sql注入问题比较感兴趣,可以看看我的另一篇文章《
卧槽,sql注入竟然把我们的系统搞挂了
》,里面有非常详细的介绍。

9 事务问题

有些小伙伴,在日常工作中,写代码时可能会忘掉事务。

特别是在更新多个表时不使用事务,数据容易出现不一致的情况。

反例:

UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;

用户1给用户2转账100元,如果不用事务,可能会出现用户1转出了100,用户2却没收到的情况。

我们使用使用START TRANSACTION命令开启事务,使用COMMIT命令提交事务。

正例:

START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;  

这样如果用户1转出100成功了,但用户2转入100失败了,则用户1的数据会回滚。

在Spring中可以使用
@Transactional
注解声明式事务,或者使用
TransactionTemplate
类这种编程式事务。

建议优先使用TransactionTemplate这种编程式事务。

10 校对规则问题

我们的表和字段上,有个COLLATE参数,可以配置校对规则。

它主要包含了三种:

  • 以_ci结尾的。
  • 以_bin结尾的。
  • 以_cs结尾的。

ci是case insensitive的缩写,意思是大小写不敏感,即忽略大小写。

cs是case sensitive的缩写,意思是大小写敏感,即区分大小写。

还有一种是bin,它是将字符串中的每一个字符用二进制数据存储,区分大小写。

使用最多的是 utf8mb4_general_ci(默认的)和 utf8mb4_bin。

我们的brand表在创建表的时候,使用的COLLATE是utf8mb4_general_ci,它不区分大小写。

CREATE TABLE `brand` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `name` varchar(30) NOT NULL COMMENT '品牌名称',
  `create_user_id` bigint NOT NULL COMMENT '创建人ID',
  `create_user_name` varchar(30) NOT NULL COMMENT '创建人名称',
  `create_time` datetime(3) DEFAULT NULL COMMENT '创建日期',
  `update_user_id` bigint DEFAULT NULL COMMENT '修改人ID',
  `update_user_name` varchar(30)  DEFAULT NULL COMMENT '修改人名称',
  `update_time` datetime(3) DEFAULT NULL COMMENT '修改时间',
  `is_del` tinyint(1) DEFAULT '0' COMMENT '是否删除 1:已删除 0:未删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci  COMMENT='品牌表';

这样在使用下面sql语句查询数据时:

select * from brand where `name`='yoyo';

就能把大写的YOYO查出来。

如果我们的表中设置的COLLATE是不区分大小写,但是业务代码中,却区分了大小写,二者不一致,就可能会出问题。

这时候,在业务代码中,就不能直接使用equals方法判断字符串是否相同,而应该改成equalsIgnoreCase方法了。

11 使用过多的 SELECT *

有些小伙伴,在写的sql语句中,习惯性使用
select *
,一次性查询所有的字段。

反例:

SELECT * FROM orders;  

这种做法每次都会查出很多没用的字段,不仅浪费带宽,也增加了查询开销。

好的做法是,每次只查询要用到的字段。

正例:

SELECT id, total FROM orders;  

我们的业务中,只需要用到id和total字段的数据,其他的字段就可以无需查询。

12 索引失效

不知道你有没有遇到过,生成环境明明创建了索引,但数据库在执行SQL的过程中,索引竟然失效了。

由于索引失效,让之前原本很快的操作,一下子变得很慢,影响了接口的性能。

我们可以通过explain关键字,查看sql的执行计划,可以确认索引是否失效。

如果索引失效了,可能是哪些原因导致的问题呢?

下面这张图给大家列举了常见原因:

想进一步了解索引失效问题的小伙伴,可以看一下我的另一篇文章《
聊聊索引失效的10种场景,太坑了
》,里面有非常详细的介绍。

13 频繁修改表或数据

在高并发场景下,频繁添加、修改字段,或者批量更新数据,导致系统性能下降。

我们在使用alter添加或者修改表字段,或者使用update批量更新,或者使用delete批量删除数据时,都可能会锁表。

如果此时正好有大量的用户请求过来了,会导致系统响应变慢。

在高并发场景下,update或者delete的数据量,不要太多,可以分批,多次执行。

对于一些alter或drop修改表结构的操作,应该避免在用户高峰期执行,最好选择在凌晨,用户少的时候执行。

此外,可以使用Percona Toolkit、gh-ost等在线工具,可以在不锁表的情况下,进行alter操作。

14 没有定期备份

在工作中,最怕遇到猪队友误删数据。

我遇到过好几次。

将测试环境的表中的数据全删了。

数据全没了就后悔,太晚了。

建议定期备份,使用
mysqldump

mysqldump -u root -p database_name > backup.sql

我们可以写一个定时任务,每个一段时间,比如:一天或,备份一次数据。

后面如果哪天又被误删数据了,可以直接通过mysql命令,将数据还原。

15 忘了归档历史数据

有些小伙伴,经常吐槽,表中的历史数据太多,查询速度像蜗牛一样慢。

这时候,我们需要将历史数据归档了。

用户一般最关心的是最近:一个月、三个月、半年或者一年的数据。

他们极少会去查询一年以上的数据。

因此,建议将历史数据做归档。

在MySQL中只保存最新的数据,历史数据可以迁移到归档库中。

最后说一句(求关注,别白嫖我)

如果这篇文章对您有所帮助,或者有所启发的话,帮忙关注一下我的同名公众号:苏三说技术,您的支持是我坚持写作最大的动力。
求一键三连:点赞、转发、在看。
关注公众号:【苏三说技术】,在公众号中回复:进大厂,可以免费获取我最近整理的10万字的面试宝典,好多小伙伴靠这个宝典拿到了多家大厂的offer。