diff --git a/parser/parser-lib-atoms/libAtomsParser.py b/parser/parser-lib-atoms/libAtomsParser.py index f813e01f4fdb7f025736cf854f3bbc599fec2f6b..f94c19effd970ffd60c36869112c0c355c9d0ace 100644 --- a/parser/parser-lib-atoms/libAtomsParser.py +++ b/parser/parser-lib-atoms/libAtomsParser.py @@ -67,7 +67,7 @@ def parse(output_file_name): base_dir = os.path.dirname(os.path.abspath(output_file_name)) terminal_gap = LibAtomsGapParser(osio) - terminal_gap.ParseOutput(output_file_name) + terminal_gap.ParseOutput(output_file_name, base_dir) terminal_trj = terminal_gap.trj @@ -81,6 +81,68 @@ def parse(output_file_name): push(jbe, gap, 'program_name') push(jbe, gap, 'program_version', key2='GAP_params.svn_version') + # SYSTEM DESCRIPTION + refs_system_description = [] + all_frames = trj.frames # <- Initial config + trajectory + for frame in all_frames: + with open_section(jbe, 'section_system') as gid: + refs_system_description.append(gid) + # Configuration core + atom_labels = np.array(frame.ase_config.get_chemical_symbols()) + push_array_values(jbe, atom_labels, 'atom_labels') + push_array_values(jbe, frame.ase_config.get_positions(), 'atom_positions') + # CAREFUL, OBSERVE CELL CONVENTION: 1st index -> x,y,z, 2nd index -> a,b,c + # Hence use transpose here: + push_array_values(jbe, frame.ase_config.get_cell().T, 'simulation_cell') + push_array_values(jbe, frame.ase_config.get_pbc(), 'configuration_periodic_dimensions') + if frame.ase_config.has('velocities'): + push_array_values(jbe, frame.ase_config.get_velocities(), 'atom_velocities') + if frame.ase_config.has('forces'): + # TODO Wouldn't it be nicer if forces were added here? + pass + pass + + # SINGLE CONFIGURATIONS + refs_single_configuration = [] + i_frame = -1 + for frame in all_frames: + i_frame += 1 + with open_section(jbe, 'section_single_configuration_calculation') as gid: + refs_single_configuration.append(gid) + # Reference system description section + ref_system = refs_system_description[i_frame] + push_value(jbe, ref_system, 'single_configuration_calculation_to_system_ref') + # Energy + if frame.has_energy: + push_value(jbe, frame.energy, 'energy_total') # TODO Check units + # Virial + if frame.has_virial: + push_array_values(jbe, frame.virial, 'x_lib_atoms_virial_tensor') + # Forces + if frame.ase_config.has('forces'): + push_array_values(jbe, frame.ase_config.get_forces(), 'atom_forces') + # Type label + if frame.has_config_type: + push_value(jbe, frame.config_type, 'x_lib_atoms_config_type') + pass + + # GAP DESCRIPTION + if gap.has_gap_data: + with open_section(jbe, 'x_lib_atoms_section_gap') as gap_gid: + push_array_values(jbe, np.array(refs_single_configuration), 'x_lib_atoms_training_config_refs') + push_value(jbe, gap['GAP_params.label'].As(), 'x_lib_atoms_GAP_params_label') + push_value(jbe, gap['GAP_params.svn_version'].As(), 'x_lib_atoms_GAP_params_svn_version') + push_value(jbe, gap['GAP_data.do_core'].As(), 'x_lib_atoms_GAP_data_do_core') + push_value(jbe, gap['GAP_data.e0'].As(float), 'x_lib_atoms_GAP_data_e0') + push_value(jbe, gap['command_line.command_line'].As(), 'x_lib_atoms_command_line_command_line') + push_value(jbe, gap['gpSparse.n_coordinate'].As(int), 'x_lib_atoms_gpSparse_n_coordinate') + types = [int, int, int, str, float, float, float, str, str, float, str, int, int ] + keys = ['n_sparseX', 'dimensions', 'n_permutations', 'sparsified', 'signal_variance', 'signal_mean', 'covariance_type', 'label', 'sparseX_filename', 'theta', 'descriptor', 'perm.permutation', 'perm.i'] + for i,key in enumerate(keys): + push_value(jbe, gap['gpCoordinates.%s' % key].As(types[i]), 'x_lib_atoms_gpCoordinates_%s' % key.replace('.', '_')) + for key in ['alpha', 'sparseX']: + push_array_values(jbe, gap['gpCoordinates.%s' % key].As(), 'x_lib_atoms_gpCoordinates_%s' % key.replace('.', '_')) + jbe.finishedParsingSession("ParseSuccess", None) return diff --git a/parser/parser-lib-atoms/libLibAtomsParser.py b/parser/parser-lib-atoms/libLibAtomsParser.py index f11e3ada53a330df947e4442df28db6ae12495de..577ec45464f4297a4b6cd0d402ff4ef48d863e31 100644 --- a/parser/parser-lib-atoms/libLibAtomsParser.py +++ b/parser/parser-lib-atoms/libLibAtomsParser.py @@ -176,8 +176,9 @@ class LibAtomsGapParser(LibAtomsParser): super(LibAtomsGapParser, self).__init__(log) self.logtag = 'gap-xml' self.trj = None + self.has_gap_data = False return - def ParseOutput(self, output_file): + def ParseOutput(self, output_file, base_dir=''): self.Set('program_name', 'libAtoms') dom = xml.dom.minidom.parse(output_file) root = XmlGetUnique(dom, 'GAP_params') @@ -210,6 +211,7 @@ class LibAtomsGapParser(LibAtomsParser): # 'GAP_params/gpSparse' key = 'gpSparse' if key in child_nodes: + self.has_gap_data = True node = child_nodes[key][0] atts = XmlGetAttributes(node) keys = ['n_coordinate'] @@ -249,6 +251,7 @@ class LibAtomsGapParser(LibAtomsParser): n_sparseX = self['gpCoordinates.n_sparseX'].As(int) n_dim = self['gpCoordinates.dimensions'].As(int) sparseX_filename = self['gpCoordinates.sparseX_filename'].As(str) + sparseX_filename = os.path.join(base_dir, sparseX_filename) # Read alpha coefficients nodes = gp_coord_child_nodes[key] alpha_cutoff = np.zeros((n_sparseX, 2), dtype='float64') @@ -315,8 +318,31 @@ class LibAtomsFrame(LibAtomsParser): def __init__(self, log=None): super(LibAtomsFrame, self).__init__(log) self.ase_config = None + self.has_energy = False + self.energy = None + self.has_virial = False + self.virial = None + self.has_config_type = False + self.config_type = None def LoadAseConfig(self, ase_config): - self.ase_atoms = ase_config + self.ase_config = ase_config + key = 'energy' + if key in self.ase_config.info: + has_energy = True + self.energy = self.ase_config.info[key] + key = 'config_type' + if key in self.ase_config.info: + self.has_config_type = True + self.config_type = self.ase_config.info[key] + key = 'virial' + if key in self.ase_config.info: + self.has_virial = True + self.virial = np.array(self.ase_config.info[key]) + + + + + return # ===================