Esempio n. 1
0
  def test_simple(self):
    parser = smu_parser_lib.SmuParser(
        os.path.join(TESTDATA_PATH, MAIN_DAT_FILE))
    conformer, _ = next(parser.process_stage2())
    expected = get_file_contents(os.path.join(TESTDATA_PATH, ATOMIC_INPUT))
    writer = smu_writer_lib.AtomicInputWriter()

    smu_writer_lib.check_dat_formats_match(
        expected,
        writer.process(conformer).splitlines())
Esempio n. 2
0
    def __init__(self, output_path):
        """Creates AtomicInputOutputter.

    Args:
      output_path: directory to write output files to
    """
        self.output_path = output_path
        if output_path and not os.path.isdir(self.output_path):
            raise ValueError(
                'Atomic input requires directory as output path, got {}'.
                format(self.output_path))
        self.atomic_writer = smu_writer_lib.AtomicInputWriter()
def main(argv):
    if len(argv) > 1:
        raise app.UsageError('Too many command-line arguments.')

    atomic_writer = smu_writer_lib.AtomicInputWriter()

    file_count = 0
    conformer_count = 0
    mismatches = 0

    for filepath in gfile.glob(FLAGS.input_glob):
        logging.info('Processing file %s', filepath)
        file_count += 1
        smu_parser = smu_parser_lib.SmuParser(filepath)
        for conformer, _ in smu_parser.process_stage2():
            conformer_count += 1

            actual_contents = atomic_writer.process(conformer)

            expected_fn = atomic_writer.get_filename_for_atomic_input(
                conformer)
            with gfile.GFile(os.path.join(FLAGS.atomic_input_dir,
                                          expected_fn)) as expected_f:
                expected_contents = expected_f.readlines()

            try:
                smu_writer_lib.check_dat_formats_match(
                    expected_contents, actual_contents.splitlines())
            except smu_writer_lib.DatFormatMismatchError as e:
                mismatches += 1
                print(e)
                if FLAGS.output_dir:
                    with gfile.GFile(
                            os.path.join(
                                FLAGS.output_dir,
                                atomic_writer.get_filename_for_atomic_input(
                                    conformer)), 'w') as f:
                        f.write(actual_contents)

    status_str = ('COMPLETE: Read %d files, %d conformers, %d mismatches\n' %
                  (file_count, conformer_count, mismatches))

    logging.info(status_str)
    print(status_str)