infile = FileReader(("from stdin", args.input_format, f)) else: if len(sys.argv) >= 1: infile = FileReader(("from stdin", "xyz", f)) geom = Geometry(infile) target_list = [] for sub in args.targets: ndx_targets = sub.split("=")[0] target_list.append(geom.find(ndx_targets)) for i, target in enumerate(target_list): element = args.targets[i].split("=")[1] # changeElement will only change one at a time for single_target in target: geom.change_element( single_target, element, adjust_bonds=fix_bonds, adjust_hydrogens=adjust_structure ) 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))
def test_change_element(self): mol = Geometry(TestGeometry.benzene) ref = Geometry(TestGeometry.pyridine) mol.change_element("1", "N", adjust_hydrogens=True) self.assertTrue(validate(mol, ref, thresh="loose"))