def main(fns_input, fn_output): ffmol = [] for fn in fns_input: fmol = pyfant.FileMolecules() try: fmol.load(fn) print("File '{}': {} molecule{}".format( fn, len(fmol), "" if len(fmol) == 1 else "s")) ffmol.append(fmol) except: a99.get_python_logger().exception("Skipping file '{}'".format(fn)) n = len(ffmol) fout = pyfant.FileMolecules() fout.titm = "Merge of {} file{}: {}".format( n, "s" if n != 1 else "", ", ".join([os.path.split(fmol.filename)[1] for fmol in ffmol])) for fmol in ffmol: fout.molecules.extend(fmol.molecules) print("Number of molecules in output: {}".format(len(fout))) if fn_output is None: fn_output = a99.new_filename(_PREFIX, ".dat") fout.save_as(fn_output) print("Saved file '{}'".format(fn_output))
def make_file_molecules(self, lines): """ Builds a FileMolecules object Args: lines: in most cases, a DataFile instance, but may be anything, since the molecular lines data extraction is performed by a particular descendant class. For example, the HITRAN converter expects a structure from the HAPI Returns: f, log: FileMolecules, MolConversionLog instances """ # Runs specific conversor to SetOfLines sols, log = self._make_sols(lines) assert isinstance(sols, ConvSols) assert isinstance(log, MolConversionLog) sols_list = list(sols.values()) sols_list.sort(key= lambda sol: sol.vl*1000+sol.v2l) mol = pyfant.molconsts_to_molecule(self.molconsts) mol.sol = sols_list f = pyfant.FileMolecules() now = datetime.datetime.now() f.titm = "PFANT molecular lines file. Created by f311.convmol.Conv.make_file_molecules() @ {}".format(now.isoformat()) f.molecules = [mol] return f, log
def _open_mol_clicked(self): filename = self.w_out.value if len(filename) > 0: f = pyfant.FileMolecules() f.load(filename) vis = pyfant.VisMolecules() vis.use(f)
def test_FileMolecules(tmpdir): os.chdir(str(tmpdir)) m = pyfant.Molecule() sol = pyfant.SetOfLines() sol.append_line(2000., .25, 10.5, "P") sol.append_line(1000., .25, 10.5, "Q1") m.sol = [sol] sol = pyfant.SetOfLines() sol.append_line(3000., .125, 13.5, "R21") m.sol.append(sol) f = pyfant.FileMolecules() f.molecules = [m] assert f.llzero == 1000. assert f.llfin == 3000. assert f.num_lines == 3 assert f.num_sols == 2 f.lmbdam f.sj f.jj f.branch f.qqv f.ggv f.bbv f.ddv f.fe f.do f.mm f.am f.ua f.ub f.te f.cro f.s f.cut(500, 1500) assert f.num_lines == 1 assert f.num_sols == 1 m.symbols = ["We", "Ur"] assert m.formula == "WeUr" f.save_as("qq")
parser = argparse.ArgumentParser(description=__doc__, formatter_class=a99.SmartFormatter) parser.add_argument('llzero', type=float, nargs=1, help='lower wavelength boundary (angstrom)') parser.add_argument('llfin', type=float, nargs=1, help='upper wavelength boundary (angstrom)') parser.add_argument('fn_input', type=str, help='input file name', nargs=1) parser.add_argument('fn_output', type=str, help='output file name', nargs=1) args = parser.parse_args() file_molecules = pyfant.FileMolecules() file_molecules.load(args.fn_input[0]) lmbdam = file_molecules.lmbdam m, M = min(lmbdam), max(lmbdam) print("Original interval: [%g, %g]" % (m, M)) print("New interval: [%g, %g]" % (args.llzero[0], args.llfin[0])) file_molecules.cut(args.llzero[0], args.llfin[0]) file_molecules.save_as(args.fn_output[0]) print("Successfully created file '%s'" % args.fn_output[0])
a99.logging_level = logging.INFO a99.flag_log_file = True if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__, formatter_class=a99.SmartFormatter) parser.add_argument('fn1', type=str, help='input file name', nargs=1) parser.add_argument('fn2', type=str, help='output file name', nargs=1) args = parser.parse_args() fn1 = args.fn1[0] fn2 = args.fn2[0] fa = pyfant.FileMolecules() fa.load(fn1) fb = pyfant.FileMolecules() fb.load(fn2) data = [] header = [fn1, fn2] def append_data(objname, attrname, value0, value1): """Appends difference""" data.append([ "{}.{} = {}".format(objname, attrname, value0), "{}.{} = {}".format(objname, attrname, value1) ])
c.conf.opt.no_h = True c.conf.opt.no_atoms = True c.conf.opt.allow = True c.conf.opt.fwhm = 0.14 return c if __name__ == "__main__": print("loading '{}'...".format(FN_OBS)) sp = f311.load_spectrum(FN_OBS) sp_lam_min = min(sp.wavelength) sp_lam_max = max(sp.wavelength) c = get_combo() f = pyfant.FileMolecules() f.load(c.conf.opt.fn_molecules) formulas = Counter() jobs = [] for molecule in f: llzero = max(sp_lam_min, min(molecule.lmbdam)) llfin = min(sp_lam_max, max(molecule.lmbdam)) if llzero >= llfin: print( "Molecule {} - {} skipped because of wavelength range being out of that of observed spectrum" .format(molecule.formula, molecule.description)) f1 = pyfant.FileMolecules() f1.molecules.append(molecule)
#!/usr/bin/env python """Molecular lines file editor.""" import sys import argparse import logging import pyfant import a99 if __name__ == "__main__": a99.logging_level = logging.INFO a99.flag_log_file = True parser = argparse.ArgumentParser(description=__doc__, formatter_class=a99.SmartFormatter) parser.add_argument('fn', type=str, help='molecules file name', default=pyfant.FileMolecules.default_filename, nargs='?') args = parser.parse_args() m = pyfant.FileMolecules() m.load(args.fn) app = a99.get_QApplication([]) form = pyfant.XFileMolecules() form.show() form.load(m) sys.exit(app.exec_())
"""Runs synthesis for molecular species separately. No atomic nor hydrogen lines.""" import matplotlib.pyplot as plt import a99 import pyfant import f311 SUBPLOT_NUM_ROWS = 2 SUBPLOT_NUM_COLS = 2 if __name__ == "__main__": pyfant.copy_star(starname="sun-grevesse-1996") pyfant.link_to_data() # Loads full molecular lines file fmol = pyfant.FileMolecules() fmol.load() runnables = [] for molecule in fmol: fmol2 = pyfant.FileMolecules() fmol2.molecules = [molecule] ecombo = pyfant.Combo() # Overrides file "molecules.dat" with in-memory object ecombo.conf.file_molecules = fmol2 ecombo.conf.flag_output_to_dir = True oo = ecombo.conf.opt # Assigns synthesis range to match atomic lines range oo.llzero, oo.llfin = fmol2.llzero, fmol2.llfin # Turns off hydrogen lines