Skip to content

Commit cb61790

Browse files
committed
Add get_reaxff_content
1 parent 9edd6cb commit cb61790

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

vaspy/atomco.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
import numpy as np
1919

20-
from vaspy import VasPy
21-
from vaspy.errors import CarfileValueError
22-
from vaspy.functions import *
20+
from . import VasPy
21+
from .errors import CarfileValueError
22+
from .functions import *
23+
from .elements import chem_elements
2324

2425

2526
class AtomCo(VasPy):
@@ -228,6 +229,38 @@ def get_cif_content(self):
228229

229230
return content
230231

232+
def get_reaxff_content(self):
233+
"""
234+
Get ReaxFF data file content
235+
"""
236+
content = '# Created by VASPy\n\n'
237+
238+
# Info
239+
content += '{} atoms\n{} atom types\n\n'.format(len(self.data),
240+
len(self.atom_types))
241+
content += '0 25.000 xlo xhi\n0 25.000 ylo yhi\n0 25.000 zlo zhi\n\n'
242+
243+
# Masses
244+
content += 'Masses\n\n'
245+
for i, element in enumerate(self.atom_types):
246+
if element not in chem_elements:
247+
raise ValueError('element {} not in elements.py'.format(element))
248+
mass = chem_elements[element]['mass']
249+
content += '{} {:.4f}\n'.format(i+1, mass)
250+
251+
# Coordinate
252+
content += '\nAtoms\n\n'
253+
cart_coords = self.dir2cart(self.bases, self.data).tolist()
254+
255+
for i, (component, coord) in enumerate(zip(self.atom_components, cart_coords)):
256+
template = '{:>4d}{:>2d}{:>4.1f}{:>9.5f}{:>11.5f}{:>11.5f}\n'
257+
idx = i+1
258+
type_idx = self.atom_types.index(component) + 1
259+
x, y, z = coord
260+
content += template.format(idx, type_idx, 0.0, x, y, z)
261+
262+
return content
263+
231264
def get_volume(self):
232265
"""
233266
Get volume of slab(Angstrom^3)

vaspy/elements.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
''' Module to store chemical elements related data.
2+
'''
3+
C12 = 1.99264648e-26 # mass of C12 (kg/atom)
4+
amu = 1.66053904e-27 # atomic mass unit (kg)
5+
6+
chem_elements = {}
7+
chem_elements['H'] = dict(index=1, mass=1.00794)
8+
chem_elements['C'] = dict(index=6, mass=12.0107)
9+
chem_elements['N'] = dict(index=7, mass=14.0067)
10+
chem_elements['O'] = dict(index=8, mass=15.9994)
11+
chem_elements['F'] = dict(index=9, mass=18.9984032)
12+
chem_elements['Ne'] = dict(index=10, mass=20.1797)
13+
chem_elements['S'] = dict(index=16, mass=32.065)
14+
chem_elements['Cl'] = dict(index=17, mass=35.453)
15+
chem_elements['Ni'] = dict(index=28, mass=58.693)
16+

vaspy/matstudio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def get_atom_info(self):
120120
tf = []
121121
tf_dict = {}
122122
atom_names = []
123+
atom_components = []
123124
atom_name_dict = {}
124125

125126
identity_mappings = self.__get_identity_mappings()
@@ -131,6 +132,7 @@ def get_atom_info(self):
131132
for elem in identity_mapping.iter('Atom3d'):
132133
# Atom name and number
133134
atom = elem.attrib['Components']
135+
atom_components.append(atom)
134136
if atom not in natoms_dict:
135137
natoms_dict.setdefault(atom, 1)
136138
atom_types.append(atom)
@@ -193,6 +195,7 @@ def get_atom_info(self):
193195
self.atom_types = atom_types
194196
self.tf = np.array(tf)
195197
self.atom_names = atom_names
198+
self.atom_components = atom_components
196199
self.atom_names_dict = atom_name_dict
197200
self.data = np.array(coordinates)
198201

0 commit comments

Comments
 (0)