def main(args): geom_patt = re.compile("([A-Z][a-z]*)((?:\s+-?\d+\.?\d*){3})") float_patt = re.compile("-?\d+\.?\d*") all_names = [] atoms = [] name = None for i, page in enumerate(extract_pages(args.infile)): print("parsing page {: 4d} please wait...".format(i + 1), end="\r") for element in page: last_line = None if hasattr(element, "get_text"): for line in element: text = line.get_text() match = geom_patt.search(text) if not match and last_line and atoms: name_match = geom_patt.search(name) if name_match: geom = Geometry(all_names[-1] + ".xyz") geom.atoms.extend(atoms) else: geom = Geometry(atoms) geom.name = name geom.comment = name if args.directory != "CURRENTDIR": geom.name = os.path.join( args.directory, geom.name) orig_name = geom.name i = 2 while geom.name in all_names: geom.name = "{}_{:03d}".format(orig_name, i) i += 1 if args.sort: geom.refresh_connected() geom.refresh_ranks() geom.atoms = geom.reorder()[0] geom.write() all_names.append(geom.name) atoms = [] name = None # print() # print(geom.name, len(geom.atoms)) # print(geom) if match: if not name: name = last_line element = match.group(1) coords = float_patt.findall(match.group(2)) atoms.append(Atom(element, [float(c) for c in coords])) last_line = text.strip()
def save_aarontools(session, path, format_name, **kwargs): """ save XYZ file using AaronTools kwargs may be: comment - str """ from SEQCROW.residue_collection import ResidueCollection from AaronTools.geometry import Geometry from chimerax.atomic import AtomicStructure accepted_kwargs = ['comment', 'models'] unknown_kwargs = [kw for kw in kwargs if kw not in accepted_kwargs] if len(unknown_kwargs) > 0: raise RuntimeWarning("unrecognized keyword%s %s?" % ("s" if len(unknown_kwargs) > 1 else "", ", ".join(unknown_kwargs))) if 'models' in kwargs: models = kwargs['models'] else: models = None if models is None: models = session.models.list(type=AtomicStructure) models = [m for m in models if isinstance(m, AtomicStructure)] if len(models) < 1: raise RuntimeError('nothing to save') res_cols = [ResidueCollection(model) for model in models] atoms = [] for res in res_cols: atoms.extend(res.atoms) geom = Geometry(atoms) if 'comment' in kwargs: geom.comment = kwargs[comment] geom.write(outfile=path)
default=[''], \ required=False, \ dest='comment', \ help='comment line') args = xyz_parser.parse_args() for f in args.infile: if isinstance(f, str): if args.input_format is not None: infile = FileReader((f, args.input_format[0], None)) else: infile = FileReader(f) else: if args.input_format is not None: infile = FileReader(('from stdin', args.input_format[0], f)) else: if len(sys.argv) >= 1: xyz_parser.print_help() raise RuntimeError("when no input file is given, stdin is read and a format must be specified") geom = Geometry(infile) if args.comment[0]: geom.comment = args.comment[0] else: geom.comment=f s = FileWriter.write_xyz(geom, append=True, outfile=args.outfile[0]) if not args.outfile[0]: print(s)
for t in ts: dEdt = S.dE_func(t)*S.dE_func(t+dt) if dEdt <= 0 and S.dE_func(t) > 0 and args.print_max: max_n_min_ts.append(t) if dEdt <= 0 and S.dE_func(t) < 0 and args.print_min: max_n_min_ts.append(t) for i, t in enumerate(max_n_min_ts): E = S.E_func(t) if args.print_E: dE = S.dE_func(t) nrg_out += "%f\t%f\t%f\n" % (t,E,dE) else: G = S.Geom_func(t) comment = "E(%f) = %f" % (t, E) G.comment = comment write_geoms.append(G.copy()) if args.specific_ts: #print structures for specified values of t for i, t in enumerate(args.specific_ts): if args.print_E: E = S.E_func(t) dE = S.dE_func(t) nrg_out += "%f\t%f\t%f\n" % (t,E,dE) else: G = S.Geom_func(t) E = S.E_func(t) comment = "E(%f) = %f" % (t, E) G.comment = comment write_geoms.append(G.copy())
if args.input_format is not None: infile = FileReader(("from stdin", args.input_format, f)) else: infile = FileReader(("from stdin", "xyz", f)) geom = Geometry(infile) # align rmsd = geom.RMSD(ref_geom, align=True, targets=args.in_target, ref_targets=args.ref_target, heavy_only=args.heavy, sort=args.sort) geom.comment = "rmsd = %f" % rmsd if not args.value_only and not args.csv: if args.outfile: outfile = args.outfile if "$INFILE" in outfile: outfile = outfile.replace("$INFILE", get_filename(f)) geom.write(append=True, outfile=outfile) else: print(geom.write(outfile=False)) elif args.value_only: if args.outfile: outfile = args.outfile if "$INFILE" in outfile: outfile = outfile.replace("$INFILE", get_filename(f))
for t in ts: dnrg_dt = pathway.dvar_func_dt["energy"](t) * pathway.dvar_func_dt["energy"](t + dt) if dnrg_dt <= 0 and pathway.dvar_func_dt["energy"](t) > 0 and args.print_max: max_n_min_ts.append(t) elif dnrg_dt <= 0 and pathway.dvar_func_dt["energy"](t) < 0 and args.print_min: max_n_min_ts.append(t) for i, t in enumerate(max_n_min_ts): nrg = pathway.var_func["energy"](t) if args.print_E: d_nrg = pathway.dvar_func_dt["energy"](t) nrg_out += "%f\t%f\t%f\n" % (t, nrg, d_nrg) else: geom = pathway.geom_func(t) comment = "E(%f) = %f" % (t, nrg) geom.comment = comment write_geoms.append(geom) if args.specific_ts: #print structures for specified values of t for i, t in enumerate(args.specific_ts): if args.print_E: nrg = pathway.var_func["energy"](t) d_nrg = pathway.dvar_func_dt["energy"](t) nrg_out += "%f\t%f\t%f\n" % (t, nrg, d_nrg) else: geom = pathway.geom_func(t) nrg = pathway.var_func["energy"](t) comment = "E(%f) = %f" % (t, nrg) geom.comment = comment write_geoms.append(geom)
s += "%s\n" % formula for group in structures[n_atoms][formula]: total += len(group) if args.directory: dir_name = os.path.join( args.directory, formula, get_filename(group[0][0].name, include_parent_dir=False), ) if not os.path.exists(dir_name): os.makedirs(dir_name) for geom, rmsd, _ in group: geom.comment = "RMSD from %s = %.4f" % ( get_filename(group[0][0].name, include_parent_dir=False), rmsd, ) if args.energy_filter and all( "energy" in g.other for g in [geom, group[0][0]]): d_nrg = UNIT.HART_TO_KCAL * ( geom.other["energy"] - group[0][0].other["energy"]) geom.comment += " energy from %s = %.1f kcal/mol" % ( get_filename(group[0][0].name, include_parent_dir=False), d_nrg, ) geom.write(outfile=os.path.join( args.directory, formula, get_filename(group[0][0].name, include_parent_dir=False),
args = xyz_parser.parse_args() for f in glob_files(args.infile, parser=xyz_parser): if isinstance(f, str): if args.input_format is not None: infile = FileReader((f, args.input_format, None)) else: infile = FileReader(f) else: if args.input_format is not None: infile = FileReader(("from stdin", args.input_format, f)) else: if len(sys.argv) >= 1: infile = FileReader(("from stdin", "xyz", f)) geom = Geometry(infile, refresh_connected=False, refresh_ranks=False) if args.comment: geom.comment = args.comment else: geom.comment = f if not args.outfile: print(geom.write(outfile=False)) else: outfile = args.outfile if "$INFILE" in outfile: outfile = outfile.replace("$INFILE", get_filename(f)) geom.write(append=args.append, outfile=outfile)