Commit 82c3ae96 authored by Mikkel Strange's avatar Mikkel Strange

constraints in asap/ase

parent 8d14c307
import numpy as np
names_plane = {0: 'fix_yz', 1: 'fix_xz', 2: 'fix_xy'}
names_line = {0: 'fix_x', 1: 'fix_y', 2: 'fix_z'}
def get_index(v):
v /= np.linalg.norm(v)
v2 = v * v
perm = v2.argsort()
d = perm[2]
return d
def get_nomad_name(c):
"""This tries to find the appropriate named name from
the constaints giving by a direction"""
constraint = c.todict()
if constraint['name'] == 'FixedPlane':
d = get_index(c.dir)
return names_plane[d]
elif constraint['name'] == 'FixedLine':
d = get_index(c.dir)
return names_line[d]
elif constraint['name'] == 'FixedAtoms':
return 'fix_xyz'
......@@ -2,9 +2,9 @@ from __future__ import division
import os
from contextlib import contextmanager
import numpy as np
from ase.data import chemical_symbols
from ase.io.aff import affopen as Reader
from ase.io.trajectory import Trajectory
import setup_paths
from constraint_conversion import get_nomad_name
from nomadcore.unit_conversion.unit_conversion import convert_unit as cu
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
......@@ -38,32 +38,46 @@ metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
def parse(filename):
p = JsonParseEventsWriterBackend(metaInfoEnv)
o = open_section
r = Reader(filename)
t = Trajectory(filename, 'r')
p.startedParsingSession(filename, parser_info)
with o(p, 'section_run'):
p.addValue('program_name', 'ASAP')
p.addValue('program_version', '1.0.0')
with o(p, 'section_system'):
p.addArrayValues('simulation_cell', c(r.cell, 'angstrom'))
symbols = np.array([chemical_symbols[z] for z in r.numbers])
p.addArrayValues('atom_labels', symbols)
p.addArrayValues('atom_positions', c(r.positions, 'angstrom'))
p.addArrayValues('configuration_periodic_dimensions',
np.array(r.pbc, bool))
with o(p, 'section_topology'):
p.addValue('topology_force_field_name', 'EMT')
with o(p, 'section_constraint'):
indices = []
for constraint in t[0].constraints:
indices.extend(constraint.get_indices())
p.addArrayValues('constraint_atoms',
np.asarray(indices))
p.addValue('constraint_kind', get_nomad_name(constraint))
with o(p, 'section_frame_sequence'):
for f in t:
with o(p, 'section_system'):
p.addArrayValues('simulation_cell',
f.get_cell(),
'angstrom')
p.addArrayValues('atom_labels',
np.asarray(t[0].get_chemical_symbols()))
p.addArrayValues('atom_positions',
c(f.get_positions(),
'angstrom'))
p.addArrayValues('configuration_periodic_dimensions',
f.get_pbc())
p.addArrayValues('atom_velocities', f.get_velocities())
with o(p, 'section_single_configuration_calculation'):
p.addRealValue('energy_total',
c(f.get_total_energy(), 'eV'))
p.addArrayValues('atom_forces',
c(f.get_forces(), 'angstrom/eV'))
with o(p, 'section_sampling_method'):
p.addValue('ensemble_type', 'NVE')
with o(p, 'section_frame_sequence'):
pass
for f in r:
with o(p, 'section_single_configuration_calculation'):
p.addRealValue('energy_total',
c(f.calculator.energy, 'eV'))
p.addArrayValues('atom_forces',
c(f.calculator.forces, 'angstrom/eV'))
with o(p, 'section_method'):
pass
# p.addValue('x_asap_electronic_structure_method', 'EMT')
# p.addValue('x_asap_electronic_structure_method', 'EMT')
p.finishedParsingSession("ParseSuccess", None)
if __name__ == '__main__':
......
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