-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathIO_lammps.py
More file actions
132 lines (92 loc) · 3.65 KB
/
Copy pathIO_lammps.py
File metadata and controls
132 lines (92 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import numpy as np
from collections import namedtuple
def lammps_writedatafile(grid,a0,t_mag):
"""
Create a string which will be written out to the LAMMPS atom data input file.
The format is as follows (<> indicate values to be filled in):
Position data for bcc Fe edge dislocation
<#atoms> atoms
<#atom types> atom types
<xlo> <xhi> xlo xhi
<ylo> <yhi> ylo yhi
<zlo> <zhi> zlo zhi
Atoms
<ind> <atom type> <m-coord> <n-coord> <t-coord>
...
Parameters
----------
grid : list of [atom index,region,m-coord,n-coord,t-coord,basis]
for each atom in the geometry
a0 : lattice constant (angstroms)
t_mag : magnitude of the periodic vector along the dislocation threading direction
i.e. slab thickness
Returns
-------
s : string which will be written out to the LAMMPS atom data input file
"""
index,reg,mcoords,ncoords,tcoords,basis = zip(*grid)
## set the size of the simulation box
xlo = np.min(mcoords)*a0 - 20 ## add at least 20 Angstroms of vacuum around the whole slab
xhi = np.max(mcoords)*a0 + 20
ylo = np.min(ncoords)*a0 - 20
yhi = np.max(ncoords)*a0 + 20
zlo = 0.
zhi = t_mag*a0
s = """Position data for dislocation
{atoms:>6} atoms
{types:>6} atom types
{xlo:>24.16f} {xhi:>24.16f} xlo xhi
{ylo:>24.16f} {yhi:>24.16f} ylo yhi
{zlo:>24.16f} {zhi:>24.16f} zlo zhi
Atoms
""".format(atoms=len(grid),types=int(np.max(basis)+1),xlo=xlo,xhi=xhi,ylo=ylo,yhi=yhi,zlo=zlo,zhi=zhi)
for atom in grid:
## write out atom index, mnt coords
s += "{index:<8d} {atomtype} {mcoord:24.16f} {ncoord:24.16f} {tcoord:24.16f}\n".format(index=int(atom.ind+1),
atomtype=int(atom.basis+1),mcoord=atom.m*a0,ncoord=atom.n*a0,tcoord=atom.t*a0)
return s
def lammps_writedatafile_reg(grid,a0,t_mag):
"""
Create a string which will be written out to the LAMMPS atom data input file.
The format is as follows (<> indicate values to be filled in):
Position data for bcc Fe edge dislocation
<#atoms> atoms
<#atom types> atom types
<xlo> <xhi> xlo xhi
<ylo> <yhi> ylo yhi
<zlo> <zhi> zlo zhi
Atoms
<ind> <region> <m-coord> <n-coord> <t-coord>
...
Parameters
----------
grid : list of [atom index,region,m-coord,n-coord,t-coord,basis]
for each atom in the geometry
a0 : lattice constant (angstroms)
t_mag : magnitude of the periodic vector along the dislocation threading direction
i.e. slab thickness
Returns
-------
s : string which will be written out to the LAMMPS atom data input file
"""
index,reg,mcoords,ncoords,tcoords,basis = zip(*grid)
## set the size of the simulation box
xlo = np.min(mcoords)*a0 - 20 ## add at least 20 Angstroms of vacuum around the whole slab
xhi = np.max(mcoords)*a0 + 20
ylo = np.min(ncoords)*a0 - 20
yhi = np.max(ncoords)*a0 + 20
zlo = 0.
zhi = t_mag*a0
s = """Position data for dislocation
{atoms:>6} atoms
{types:>6} atom types
{xlo:>24.16f} {xhi:>24.16f} xlo xhi
{ylo:>24.16f} {yhi:>24.16f} ylo yhi
{zlo:>24.16f} {zhi:>24.16f} zlo zhi
Atoms
""".format(atoms=len(grid),types=grid[-1][1],xlo=xlo,xhi=xhi,ylo=ylo,yhi=yhi,zlo=zlo,zhi=zhi)
for atom in grid:
## write out atom index, mnt coords
s += "{index:<8d} {atomtype} {mcoord:24.16f} {ncoord:24.16f} {tcoord:24.16f}\n".format(index=atom.ind+1,
atomtype=atom.reg,mcoord=atom.m*a0,ncoord=atom.n*a0,tcoord=atom.t*a0)
return s