def readSorptionDatabase(self): """ Read the sorption database """ with open('testdata/gwb_sorption_testdata.dat', 'r') as dbfile: dblist = dbfile.readlines() # Parse the database self.sorption_db = gwb_reader.readDatabase(dblist)
def main(): """ Parse the thermodynamic database and convert the data to the MOOSE JSON format Usage: database_converter.py -i filename --format format -o output_name For help text: database_converter.py --help """ # Command-line options opt = command_line_options() # Read the entire database file into a list with open(opt.input, 'r') as dbfile: dblist = dbfile.readlines() # Parse data using appropriate reader if opt.format == 'gwb': db = gwb_reader.readDatabase(dblist) elif opt.format == 'eq36': db = eq36_reader.readDatabase(dblist) # Combine all of the database data into a single dictionary database = {} # Header information database['Header'] = {} database['Header']['title'] = 'MOOSE thermodynamic database' database['Header']['original'] = os.path.abspath(opt.input) database['Header']['date'] = datetime.datetime.now().strftime( "%H:%M %d-%m-%Y") database['Header']['original format'] = db.format if db.header: database['Header']['original header'] = db.header if db.activity_model: database['Header']['activity model'] = db.activity_model if db.fugacity_model: database['Header']['fugacity model'] = db.fugacity_model database['Header']['temperatures'] = db.temperatures database['Header']['pressures'] = db.pressures if db.activity_model == 'debye-huckel': database['Header']['adh'] = db.adh database['Header']['bdh'] = db.bdh database['Header']['bdot'] = db.bdot if db.neutral_species: database['Header']['neutral species'] = db.neutral_species if db.elements: database['elements'] = db.elements if db.basis_species: database['basis species'] = db.basis_species if db.secondary_species: database['secondary species'] = db.secondary_species if db.mineral_species: database['mineral species'] = db.mineral_species if db.gas_species: database['gas species'] = db.gas_species if db.redox_couples: database['redox couples'] = db.redox_couples if db.oxides: database['oxides'] = db.oxides if db.sorbing_minerals: database['sorbing minerals'] = db.sorbing_minerals if db.surface_species: database['surface species'] = db.surface_species # Write out the database to JSON format with open(opt.output, 'w') as output: json.dump(database, output, indent=2) sys.stdout.write("Finished parsing " + opt.input + ". Output written to " + opt.output + "\n") sys.exit(0)