def run(self, mainfile: str, archive: EntryArchive, logger): # Log a hello world, just to get us started. TODO remove from an actual parser. logger.info('Hello World') # Use the previously defined parsers on the given mainfile mainfile_parser.mainfile = mainfile mainfile_parser.parse() # Output all parsed data into the given archive. run = archive.m_create(Run) run.program_name = 'super_code' run.program_version = str(mainfile_parser.get('program_version')) date = datetime.datetime.strptime( mainfile_parser.get('date'), '%Y/%m/%d') - datetime.datetime(1970, 1, 1) run.program_compilation_datetime = date.total_seconds() for calculation in mainfile_parser.get('calculation'): system = run.m_create(System) system.lattice_vectors = calculation.get('lattice_vectors') sites = calculation.get('sites') system.atom_labels = [site[0] for site in sites] system.atom_positions = [site[1] for site in sites] scc = run.m_create(SCC) scc.single_configuration_calculation_to_system_ref = system scc.energy_total = calculation.get('energy') * units.eV scc.single_configuration_calculation_to_system_ref = system magic_source = calculation.get('magic_source') if magic_source is not None: scc.x_example_magic_value = magic_source
def run(self, mainfile: str, archive: EntryArchive, logger): open_file = open if mainfile.endswith(".gz"): open_file = gzip.open elif mainfile.endswith(".bz2"): open_file = bz2.open elif mainfile.endswith(".xz"): open_file = lzma.open with open_file(mainfile, "rt") as file: contents = file.read() self.mainfile_parser.mainfile = mainfile self.mainfile_parser.parse() run = archive.m_create(Run) metadata = archive.m_create(EntryMetadata) dft = metadata.m_create(DFTMetadata) metadata.domain = "dft" metadata.mainfile = mainfile # basis set check if "plane waves" not in contents: print("Qball Error: Not a plane wave dft") dft.basis_set = "plane waves" dft.crystal_system = "cubic" dft.code_name = "qball" # get atoms metadata.atoms = self.mainfile_parser.get("atoms") run.program_name = "qball" run.time_run_date_start = str_to_timestamp( self.mainfile_parser.get("start_time")) run.time_run_date_end = str_to_timestamp( self.mainfile_parser.get("end_time")) element_tree = ElementTree.fromstring(contents) #section system system = run.m_create(System) system.atom_labels = [ atom.attrib["name"] for atom in element_tree.find("run").find( "iteration").find("atomset").iter("atom") ] system.atom_positions = np.array([[ pos_to_unit(float(pos)) for pos in atom.find("position").text.split() ] for atom in element_tree.find("run").find("iteration").find( "atomset").iter("atom")]) #section SingleConfigurationCalculation single_configuration_calculation = run.m_create( SingleConfigurationCalculation) single_configuration_calculation.atom_forces = np.array([[ force_to_unit(float(force)) for force in atom.find("force").text.split() ] for atom in element_tree.find("run").find("iteration").find( "atomset").iter("atom")])
def run(self, mainfile: str, archive: EntryArchive, logger): # Log a hello world, just to get us started. logger.info('Testing the XPS World') # Read the JSON file into a dictionary with open(mainfile, 'rt') as f: file_data = json.load(f) for item in file_data: # Create a measurement in the archive measurement = archive.m_create(Measurement) """ Create metadata schematic and import values """ metadata = measurement.m_create(Metadata) # Load entries into each heading # Sample sample = metadata.m_create(Sample) sample.sample_id = item['metadata']['sample'] sample.spectrum_region = item['metadata']['spectrum_region'] # Experiment experiment = metadata.m_create(Experiment) experiment.method_name = item['metadata']['method_type'] experiment.experiment_id = item['metadata']['experiment_id'] experiment.experiment_publish_time = datetime.now() # experiment.experiment_start_time = datetime.strptime( # item['metadata']['timestamp'], '%d-%m-%Y %H:%M:%S') # Instrument instrument = metadata.m_create(Instrument) instrument.n_scans = item['metadata']['n_scans'] instrument.dwell_time = item['metadata']['dwell_time'] instrument.excitation_energy = item['metadata'][ 'excitation_energy'] if item['metadata']['source_label'] is not None: instrument.source_label = item['metadata']['source_label'] # Origin origin = metadata.m_create(Origin) # Author author = origin.m_create(Author) author.author_name = item['metadata']['author'] author.group_name = item['metadata']['group_name'] # Data Header labels_to_match = [] for dlabel in item['metadata']['data_labels']: data_header = metadata.m_create(DataHeader) data_header.channel_id = dlabel['channel_id'] data_header.label = dlabel['label'] data_header.unit = dlabel['unit'] labels_to_match.append(dlabel['label'].replace(' ', '_')) # Import Data data = measurement.m_create(Data) for i, label in enumerate(labels_to_match): spectrum = data.m_create(Spectrum) if label == 'count': value = np.array(item['data'][i]) else: value = np.array(item['data'][i]) * ureg( item['metadata']['data_labels'][i]['unit']) setattr(spectrum, label, value)
def parse(self, mainfile: str, archive: EntryArchive, logger): self.archive = archive # Use the previously defined parsers on the given mainfile mainfile_parser.mainfile = mainfile mainfile_parser.parse() del mainfile_parser._file_handler # Get system from the MD file md_file = path.splitext(mainfile)[0] + '.md' if path.isfile(md_file): mdfile_md_steps = read_md_file(md_file) else: mdfile_md_steps = None # Some basic values run = archive.m_create(Run) run.program_name = 'OpenMX' run.program_version = str(mainfile_parser.get('program_version')) run.program_basis_set_type = "Numeric AOs" have_timing = mainfile_parser.get('have_timing') if have_timing is not None: run.run_clean_end = True else: run.run_clean_end = False self.parse_sampling_method() self.parse_method() mainfile_md_steps = mainfile_parser.get('md_step') if mainfile_md_steps is not None: n_md_steps = len(mainfile_md_steps) n_mdfile_md_steps = 0 if mdfile_md_steps is not None: n_mdfile_md_steps = len(mdfile_md_steps) # Do some consistency checks between the out and md file. ignore_md_file = False if n_mdfile_md_steps > n_md_steps: # This can happen when user runs two calculations in the same directory. # In that case the out file contains the latter calculation but the md file # would contain both calculations, so just take the corresponding number # of steps from the end of the file. mdfile_md_steps = mdfile_md_steps[-n_md_steps:] elif n_mdfile_md_steps < n_md_steps: # This is unlikely, but signals a problem with the md file, so just # ignore it. ignore_md_file = True logger.warning(".md file does not contain enough MD steps") if mainfile_md_steps is not None: for i, md_step in enumerate(mainfile_md_steps): system = run.m_create(System) if not ignore_md_file: parse_md_file(i, mdfile_md_steps, system) elif i == 0: # Get the initial position from out file as a fallback if the md file is missing. parse_structure(system, logger) scc = run.m_create(SCC) scc.single_configuration_calculation_to_system_ref = system scc.single_configuration_to_calculation_method_ref = run.section_method[ -1] scf_steps = md_step.get('SCF') if scf_steps is not None: for scf_step in scf_steps: scf = scc.m_create(SCF) u_ele = scf_step.get('Uele') if u_ele is not None: scf.energy_sum_eigenvalues_scf_iteration = u_ele * units.hartree u_tot = md_step.get('Utot') if u_tot is not None: scc.energy_total = u_tot * units.hartree if not ignore_md_file: forces = mdfile_md_steps[i].get('forces') if forces is not None: scc.atom_forces = forces * units.hartree / units.bohr temperature = mdfile_md_steps[i].get('temperature') if temperature is not None: scc.temperature = temperature * units.kelvin self.parse_eigenvalues()