Planned maintenance on Wednesday, 2021-01-20, 17:00-18:00. Expect some interruptions during that time

Commit 3354625b authored by Adam Fekete's avatar Adam Fekete

cleanup, fix wrong type definition in imported json data

parent 38d422d8
......@@ -39,3 +39,5 @@ TAGS
.idea
notebook/FF-fit_adam.bkr
notebook/FF-fit_aldo.bkr
main.py
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -56,8 +56,8 @@ class ForceConfs(DataModel):
with open(filename, 'r') as jsonfile:
data = json.load(jsonfile)['data']
confs = [np.array(timestep['confs']) for timestep in data]
force = [np.array(timestep['force']) for timestep in data]
confs = [np.array(timestep['confs'], dtype=np.float) for timestep in data]
force = [np.array(timestep['force'], dtype=np.float) for timestep in data]
self.confs = np.asarray(confs)
self.force = np.asarray(force)
......
import json
class TimeStep(object):
def __init__(self):
......@@ -24,10 +25,6 @@ class TimeStep(object):
)
# N = 207
# num_lines = sum(1 for line in open('disloiron.xyz'))
# steps = 100 # num_lines/(N+2)
N = len(self.confs)
r_cut = 5 # 3.5 4.4
......@@ -49,52 +46,51 @@ class TimeStep(object):
for i, (a2, offset) in enumerate(zip(indices, offsets)):
d = atoms.positions[a2] + offset - atoms.positions[0]
conf[i] = d
confs.append(conf)
print(confs)
cutoffs = np.ones(N) * r_cut / 2.
print(cutoffs)
nl = NeighborList(cutoffs, skin=0., sorted=False, self_interaction=False, bothways=True)
confs = []
forces = np.zeros((np.round(steps / every), 1, 3))
for n in np.arange(np.round(steps / every)):
atoms = extxyz.read_extxyz('disloiron.xyz', index=n * every)
forces[n] = atoms.get_array('force')[0]
cutoffs = np.ones(len(atoms)) * r_cut / 2.
nl = NeighborList(cutoffs, skin=0., sorted=False, self_interaction=False,
bothways=True)
nl.build(atoms)
cell = atoms.get_cell()
indices, offsets = nl.get_neighbors(0)
offsets = np.dot(offsets, cell)
conf = np.zeros((len(indices), 3))
for i, (a2, offset) in enumerate(zip(indices, offsets)):
d = atoms.positions[a2] + offset - atoms.positions[0]
conf[i] = d
confs.append(conf)
np.save("confst.npy", confs)
np.save("forcest.npy", forces)
lens = []
for i in np.arange(len(confs)):
lens.append(len(confs[i]))
print(max(lens))
print(min(lens))
print(np.mean(lens))
return conf, self.force[0]
#
# cutoffs = np.ones(N) * r_cut / 2.
# print(cutoffs)
# nl = NeighborList(cutoffs, skin=0., sorted=False, self_interaction=False, bothways=True)
#
# confs = []
# forces = np.zeros((np.round(steps / every), 1, 3))
#
# for n in np.arange(np.round(steps / every)):
# atoms = extxyz.read_extxyz('disloiron.xyz', index=n * every)
# forces[n] = atoms.get_array('force')[0]
#
# cutoffs = np.ones(len(atoms)) * r_cut / 2.
# nl = NeighborList(cutoffs, skin=0., sorted=False, self_interaction=False,
# bothways=True)
# nl.build(atoms)
#
# cell = atoms.get_cell()
#
# indices, offsets = nl.get_neighbors(0)
# offsets = np.dot(offsets, cell)
# conf = np.zeros((len(indices), 3))
#
# for i, (a2, offset) in enumerate(zip(indices, offsets)):
# d = atoms.positions[a2] + offset - atoms.positions[0]
# conf[i] = d
# confs.append(conf)
#
# np.save("confst.npy", confs)
# np.save("forcest.npy", forces)
#
# lens = []
# for i in np.arange(len(confs)):
# lens.append(len(confs[i]))
#
# print(max(lens))
# print(min(lens))
# print(np.mean(lens))
class ReadLammpsDumpFile():
......@@ -103,32 +99,32 @@ class ReadLammpsDumpFile():
self.counter = 0 # type: int
def __enter__(self):
print('enter')
# print('enter')
self.fid = open(self.filename, 'r')
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print('exit')
# print('exit')
self.fid.close()
pass
def __iter__(self):
print("iter")
# print("iter")
return self
def __next__(self):
try:
timestep = self.readtimestep()
print('next')
# print('next')
except:
raise StopIteration
if self.counter > 1:
raise StopIteration
else:
self.counter += 1
# if self.counter > 1:
# raise StopIteration
# else:
# self.counter += 1
return timestep
......@@ -137,7 +133,7 @@ class ReadLammpsDumpFile():
item = self.fid.readline()
words = item.split()[2:]
print(words)
# print(words)
confs = []
force = []
......@@ -184,24 +180,44 @@ class JsonWriter():
pass
if __name__ == '__main__':
def write_json(output, confs, forces):
# print(json.dumps({'confs': confs[0].tolist()}))
# print(json.dumps({'force': forces}))
# print(json.dumps({'confs': confs[0].tolist(), 'force': forces[0].tolist()}))
filename='data-lammps/Silic_300/Si_300_dump.atom'
out = []
for c, f in zip(confs, forces):
out.append({'confs': c.tolist(), 'force': f})
with open(output, 'w') as outfile:
json.dump({'data': out}, outfile)
if __name__ == '__main__':
filename='data-lammps/Silic_2000/Si_2000_dump.atom'
output = 'Si_2000K.json'
confs = []
forces = []
with ReadLammpsDumpFile(filename) as file:
for timestep in file:
conf, force = timestep.convert()
confs.append(conf)
forces.append(force)
print(timestep)
print(timestep.confs)
print(timestep.force)
# print(timestep)
# print(timestep.confs)
# print(timestep.force)
write_json(output, confs, forces)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment