forked from TrinkleGroup/LatticeGreenFunction_new
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
103 lines (72 loc) · 3.72 KB
/
Copy pathsetup.py
File metadata and controls
103 lines (72 loc) · 3.72 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
import numpy as np
import numpy.linalg as la
from collections import namedtuple
def readinputs(f):
"""
Reads in information from input file:
parameters related to the material and crystal structure,
followed by information related to setting up the dislocation slab geometry.
Parameters
----------
f : filename to read data from e.g. input_bccscrew
Returns
-------
crystalclass: crystal class (0=isotropic; 1=cubic; 2=hexagonal)
a0 : lattice constant in angstroms
Cijs : list of Cijs
M : 3x3 matrix for rotating from mnt basis to cartesian basis
(columns are normalized m,n,t vectors)
t_mag : magnitude of the periodic vector along the dislocation threading direction
"""
## read in lines from input file and ignore blank lines and comment lines
lines = [line.rstrip() for line in f if line.rstrip() if line[0] != '#']
# first line is the crystal class
crystalclass = int(lines[0].split()[0])
# a1,a2,a3
# A = np.array([[float(lines[1].split()[0]),float(lines[1].split()[1]),float(lines[1].split()[2])],
# [float(lines[2].split()[0]),float(lines[2].split()[1]),float(lines[2].split()[2])],
# [float(lines[3].split()[0]),float(lines[3].split()[1]),float(lines[3].split()[2])]]).T
# number of basis atoms
# num_basis = int(lines[4].split()[0])
# basis atom positions in unit cell
# unitcell_pos = []
# for i in range(num_basis):
# unitcell_pos.append([float(lines[5+i].split()[0]),float(lines[5+i].split()[1]),float(lines[5+i].split()[2])])
# lattice constant (Angstroms)
a0 = float(lines[-6].split()[0])
# elastic constants (GPa)
Cijs = [float(entry) for entry in lines[-5].split()]
# m,n,t
m = np.array([float(lines[-4].split()[0]),float(lines[-4].split()[1]),float(lines[-4].split()[2])])
n = np.array([float(lines[-3].split()[0]),float(lines[-3].split()[1]),float(lines[-3].split()[2])])
t = np.array([float(lines[-2].split()[0]),float(lines[-2].split()[1]),float(lines[-2].split()[2])])
M = np.array([m/la.norm(m),n/la.norm(n),t/la.norm(t)]).T
# t_mag
t_mag = np.sqrt(float(lines[-1].split()[0]))
return (crystalclass,a0,Cijs,M,t_mag)
def readprimitive(f):
"""
Reads in information from primitive input file.
This file is only needed if using the bulk FCs method for seeting up D.
Parameters
----------
f : filename to read data from e.g. input_bccscrew
Returns
-------
A : 3x3 matrix for rotating from primitive basis to cubic cartesian basis
(columns are a1,a2,a3 vectors)
unitcell_pos: positions of the basis atoms within the primitive unit cell
"""
## read in lines from input file and ignore blank lines and comment lines
lines = [line.rstrip() for line in f if line.rstrip() if line[0] != '#']
# a1,a2,a3
A = np.array([[float(lines[0].split()[0]),float(lines[0].split()[1]),float(lines[0].split()[2])],
[float(lines[1].split()[0]),float(lines[1].split()[1]),float(lines[1].split()[2])],
[float(lines[2].split()[0]),float(lines[2].split()[1]),float(lines[2].split()[2])]]).T
# number of basis atoms
num_basis = int(lines[3].split()[0])
# basis atom positions in unit cell
unitcell_pos = []
for i in range(num_basis):
unitcell_pos.append([float(lines[4+i].split()[0]),float(lines[4+i].split()[1]),float(lines[4+i].split()[2])])
return (A,unitcell_pos)