新建
LAMMPS计算Cu体积模量
![](https://cdn1.deepmd.net/static/img/d7d9741bda38a158-957c-4877-942f-4bf6f81fcc63.png?x-oss-process=image/resize,w_100,m_lfit)
1310819006@qq.com![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
推荐镜像 :Basic Image:ubuntu:22.04-py3.10-cuda12.1
推荐机型 :c2_m4_cpu
赞
写入Cu体积模量计算脚本
代码
文本
[39]
%%writefile in.Cu_lj_module
units metal
boundary p p p
atom_style atomic
variable i loop 40
variable x equal 3.40+0.01*$i
lattice fcc $x
region box block 0 1 0 1 0 1
create_box 1 box
create_atoms 1 box
mass 1 64
#使用LJ势函数
pair_style lj/cut 10.0
pair_coeff 1 1 0.40933 2.338 #Σ和伊布西龙 使用金属单位
variable v equal ($x)^3
variable n equal count(all)
variable P equal pe
#######运行########
run 0
print "Cohesive Energy of Cu v = $v x = $x E = $P"
clear
next i
jump SELF #重新开始运行程序
Overwriting in.Cu_lj_module
代码
文本
[40]
%%capture #capture命令禁止屏幕输出
!OMP_NUM_THREADS=2 lmp -i in.Cu_lj_module
代码
文本
[41]
!vi log.lammps
7t;4;2m="log.lammps" 3284L, 112692B▽ Pzz\ t;c]10;?]11;?LAMMPS (2 Aug 2023) using 2 OpenMP thread(s) per MPI taskLoaded 1 plugins from /opt/deepmd-kit-3.0.0/lib/deepmd_lmpunits metal boundary p p p atom_style atomic variable i loop 40 variable x equal 3.40+0.01*$i variable x equal 3.40+0.01*1 lattice fcc $x lattice fcc 3.41 Lattice spacing in x,y,z = 3.41 3.41 3.41 region box block 0 1 0 1 0 1 create_box 1 box Created orthogonal box = (0 0 0) to (3.41 3.41 3.41) 1 by 1 by 1 MPI processor grid create_atoms 1 box Created 4 atoms using lattice units in orthogonal box = (0 0 0) to (3.41 3.41 3.41) create_atoms CPU = 0.001 seconds mass 1 641,1TopType :qa and press <Enter> to exit Vim1,1Top
代码
文本
[42]
!grep "Cohesive" log.lammps
print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 39.651821 x = 3.41 E = -11.6743276227989 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 40.001688 x = 3.42 E = -11.9405476050061 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 40.353607 x = 3.43 E = -12.1595640975458 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 40.707584 x = 3.44 E = -12.3842526979336 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 41.063625 x = 3.45 E = -12.5895372366665 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 41.421736 x = 3.46 E = -12.7764125325894 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 41.781923 x = 3.47 E = -12.9458260014581 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 42.144192 x = 3.48 E = -13.0986799313477 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 42.508549 x = 3.49 E = -13.2358336452587 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 42.875 x = 3.5 E = -13.3581055567528 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 43.243551 x = 3.51 E = -13.4662751241234 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 43.614208 x = 3.52 E = -13.5610847083218 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 43.986977 x = 3.53 E = -13.6432413395693 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 44.361864 x = 3.54 E = -13.7070496808943 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 44.738875 x = 3.55 E = -13.7659953596674 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 45.118016 x = 3.56 E = -13.8142114984977 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 45.499293 x = 3.57 E = -13.852279849293 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 45.882712 x = 3.58 E = -13.8807544504762 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 46.268279 x = 3.59 E = -13.9001629355792 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 46.656 x = 3.6 E = -13.9110077784364 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 47.045881 x = 3.61 E = -13.9137674781707 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 47.437928 x = 3.62 E = -13.9088976869966 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 47.832147 x = 3.63 E = -13.8968322836988 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 48.228544 x = 3.64 E = -13.8779843955076 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 48.627125 x = 3.65 E = -13.8527473709409 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 49.027896 x = 3.66 E = -13.7961834075309 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 49.430863 x = 3.67 E = -13.759684579032 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 49.836032 x = 3.68 E = -13.7178592687278 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 50.243409 x = 3.69 E = -13.6710307078911 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 50.653 x = 3.7 E = -13.6195065548619 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 51.064811 x = 3.71 E = -13.5635796208348 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 51.478848 x = 3.72 E = -13.5035285612586 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 51.895117 x = 3.73 E = -13.4396185345301 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 52.313624 x = 3.74 E = -13.3721018295858 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 52.734375 x = 3.75 E = -13.3012184639042 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 53.157376 x = 3.76 E = -13.2271967533648 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 53.582633 x = 3.77 E = -13.1502538553272 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 54.010152 x = 3.78 E = -13.0705962862321 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 54.439939 x = 3.79 E = -12.9884204149546 print "Cohesive Energy of Cu v = $v x = $x E = $P" Cohesive Energy of Cu v = 54.872 x = 3.8 E = -12.9039129330838
代码
文本
[45]
import re
data = []
pattern = re.compile(r"Cohesive Energy of Cu v = ([\d\.-]+)\s+x = ([\d\.-]+)+\s+E = ([\d\.-]+)")
with open("./log.lammps", "r") as file:
for line in file:
match = pattern.search(line)
if match:
v_value = float(match.group(1))
x_value = float(match.group(2))
E_value = float(match.group(3))
data.append((v_value,x_value, E_value))
len(data)
40
代码
文本
[46]
with open ("Cu_fcc.csv","w") as f:
f.write("v, x, E\n")
for v,x,E in data:
f.write(f"{v},{x},{E}\n")
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
file_name = "Cu_fcc.csv"
data_frame = pd.read_csv(file_name)
data_frame
v | x | E | |
---|---|---|---|
0 | 39.651821 | 3.41 | -11.674328 |
1 | 40.001688 | 3.42 | -11.940548 |
2 | 40.353607 | 3.43 | -12.159564 |
3 | 40.707584 | 3.44 | -12.384253 |
4 | 41.063625 | 3.45 | -12.589537 |
5 | 41.421736 | 3.46 | -12.776413 |
6 | 41.781923 | 3.47 | -12.945826 |
7 | 42.144192 | 3.48 | -13.098680 |
8 | 42.508549 | 3.49 | -13.235834 |
9 | 42.875000 | 3.50 | -13.358106 |
10 | 43.243551 | 3.51 | -13.466275 |
11 | 43.614208 | 3.52 | -13.561085 |
12 | 43.986977 | 3.53 | -13.643241 |
13 | 44.361864 | 3.54 | -13.707050 |
14 | 44.738875 | 3.55 | -13.765995 |
15 | 45.118016 | 3.56 | -13.814211 |
16 | 45.499293 | 3.57 | -13.852280 |
17 | 45.882712 | 3.58 | -13.880754 |
18 | 46.268279 | 3.59 | -13.900163 |
19 | 46.656000 | 3.60 | -13.911008 |
20 | 47.045881 | 3.61 | -13.913767 |
21 | 47.437928 | 3.62 | -13.908898 |
22 | 47.832147 | 3.63 | -13.896832 |
23 | 48.228544 | 3.64 | -13.877984 |
24 | 48.627125 | 3.65 | -13.852747 |
25 | 49.027896 | 3.66 | -13.796183 |
26 | 49.430863 | 3.67 | -13.759685 |
27 | 49.836032 | 3.68 | -13.717859 |
28 | 50.243409 | 3.69 | -13.671031 |
29 | 50.653000 | 3.70 | -13.619507 |
30 | 51.064811 | 3.71 | -13.563580 |
31 | 51.478848 | 3.72 | -13.503529 |
32 | 51.895117 | 3.73 | -13.439619 |
33 | 52.313624 | 3.74 | -13.372102 |
34 | 52.734375 | 3.75 | -13.301218 |
35 | 53.157376 | 3.76 | -13.227197 |
36 | 53.582633 | 3.77 | -13.150254 |
37 | 54.010152 | 3.78 | -13.070596 |
38 | 54.439939 | 3.79 | -12.988420 |
39 | 54.872000 | 3.80 | -12.903913 |
代码
文本
[55]
lat = np.array(data_frame['v'])
ene = np.array(data_frame[' E'])
a, b, c = np.polyfit(lat, ene, 2)
mesh = np.linspace(np.min(lat),np.max(lat),1000)
opt_lat = -b/(2*a)
Emin = np.polyval([a,b,c], opt_lat)
print("a,b,c=", a, b, c )
print("Emin = ", Emin, "opt_lat = ", opt_lat)
plt.scatter(lat, ene, 10)
plt.plot(mesh, a*mesh**2+b*mesh +c)
plt.xlabel("volume")
plt.ylabel("Energy")
plt.show()
a,b,c= 0.027859136511323872 -2.677008042125913 50.35779796262389 Emin = -13.951195019749292 opt_lat = 48.04542382420561
代码
文本
二次多项式拟合效果较差选用BM方程进行拟合
代码
文本
[63]
v = np.array(data_frame['v'])
e = np.array(data_frame[' E'])
a, b, c = np.polyfit(v, e, 2)
v0 = -b/(2*a)
b0 = 2*a*v0
e0 = a*v0**2 +b*v0+c
bp =3.5
x0 = [e0, b0, bp, v0]
def Murnaghan(parameters ,vol):
E0 = parameters[0]
B0 = parameters[1]
BP = parameters[2]
V0 = parameters[3]
E = E0+ B0*vol/BP*(((v0/vol)**BP)/(BP-1)+1)-V0*B0/(BP-1.)
return E
def residual(pars, y, x):
err = y - Murnaghan(pars,x)
return err
from scipy.optimize import leastsq
murnpars, ier = leastsq(residual, x0, args=(e,v))
v_mesh = np.linspace(np.min(v),np.max(v),1000)
#输出结果
print("Bulk Modulus :"+ str(murnpars[1]))
#print("Lattice constant: "+ murnpars[3]**(1/3))
plt.scatter(v, e, 10)
plt.plot(v_mesh, Murnaghan(murnpars, v_mesh))
plt.ylabel("Energy")
plt.xlabel("Volume")
plt.show()
Bulk Modulus :2.43855493304413
代码
文本
[64]
%%bash
## 这行命令可以下载 lammps安装包中,potentials文件夹下的所有势函数,用于后续eam势函数的导入
wget https://bohrium-api.dp.tech/ds-dl/lammps-potentials-8snt-v1.zip
unzip -o ./lammps-potentials-8snt-v1.zip
已隐藏输出
代码
文本
居然和二次函数一样
代码
文本
[65]
%%bash
## 查看 potentials 文件夹中自带的势函数
cd potentials && ls
已隐藏输出
代码
文本
[ ]
代码
文本
点个赞吧
本文被以下合集收录
分子动力学![](https://cdn1.deepmd.net/static/img/d7d9741bda38a158-957c-4877-942f-4bf6f81fcc63.png?x-oss-process=image/resize,w_100,m_lfit)
![](https://cdn1.deepmd.net/static/img/d7d9741bda38a158-957c-4877-942f-4bf6f81fcc63.png?x-oss-process=image/resize,w_100,m_lfit)
fish![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
更新于 2024-04-09
3 篇0 人关注
推荐阅读
公开
刘丰硕-第7天-2403-计算材料学实战![](https://cdn1.deepmd.net/static/img/d7d9741bda38a158-957c-4877-942f-4bf6f81fcc63.png?x-oss-process=image/resize,w_100,m_lfit)
bohr354e95![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
发布于 2024-03-15
1 转存文件
公开
张学丽-第7天-2403-计算材料学实战![](https://cdn1.deepmd.net/static/img/d7d9741bda38a158-957c-4877-942f-4bf6f81fcc63.png?x-oss-process=image/resize,w_100,m_lfit)
ZXL![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
![](https://cdn1.deepmd.net/bohrium/web/static/images/level-v2-1.png?x-oss-process=image/resize,w_50,m_lfit)
发布于 2024-03-15