/
cast.py
87 lines (71 loc) · 2.96 KB
/
cast.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 6 01:11:32 2018
Shape related operations
@author: rakesh
"""
from commands import *
def read_poscar(layers, atom_dict):
from pymatgen import Structure, Element
from objects import atom
name = (input('Enter Name of POSCAR file in the same directory: '))
poscar = Structure.from_file(name)
for i in poscar:
mg_atom = Element(str(i.specie))
atom_dict[len(atom_dict)] = atom(mg_atom, list(i.coords), num=len(atom_dict), c_tag='b')
layers.append([atom_dict[i] for i in atom_dict])
print('Read POSCAR as a single layer')
cmd = input('add layer <l> or add adsorbate <a>? ')
while cmd == 'l':
sym = input("Which atom to deposit? ")
add_layer(Element(sym))
cmd = input('add layer <l> or add adsorbate <a>? ')
if cmd == 'a':
add_ads(layers[-1], Element(sym))
def read_instructions(layers, atom_dict):
import pymatgen as mg
f = open('instructions.txt', 'r')
ctr = 0
for line in f:
# Each command is sent a pymatgen object
# commands are sent last layer or all layers as needed
if line.startswith('shape'):
shape = line.split()[1]
shape_atom = mg.Element(line.split()[2])
read_shape(shape, shape_atom, layers, atom_dict)
elif line.startswith('layer'):
add_layer(layers[-1], mg.Element(line.split()[1]))
elif line.startswith('ads'):
add_ads(layers, mg.Element(line.split()[1]))
elif line.startswith('mads'):
add_mads(layers, line.split[1])
elif line.startswith('done'):
create_poscar(layers, str(ctr))
else:
print('Could not read instructions file')
def read_shape(shape, shape_atom, layers, atom_dict):
import numpy as np
import pymatgen as mg
import os
from objects import atom
dir_path = os.path.dirname(os.path.realpath(__file__))
# opening shapes file
with open(os.path.join(dir_path, 'shapes/' + shape)) as f:
tag = f.readline()
try: c = int(tag.split()[1])
except IndexError: c=0
mg_atom=mg.Element(shape_atom)
# adding core layer if specified
for j in range(c):
coords = np.array(list(map(float, f.readline().split())))*mg_atom.atomic_radius
atom_dict[len(atom_dict)] = atom(mg_atom, coords, num=len(atom_dict), c_tag='b')
# adding given layers to global layers list
layers.append([atom_dict[i] for i in range(c)])
print('Core layer created, atoms:', len(layers[0]))
# adding outer shell (rest of the atoms)
for line in f:
coords = np.array(list(map(float, line.split())))*float(mg_atom.atomic_radius)
atom_dict[len(atom_dict)] = atom(mg_atom, coords, num=len(atom_dict), c_tag='b')
layers.append([atom_dict[i] for i in range(c, len(atom_dict))])
print('Shell layer created, atoms:', len(layers[-1]))