|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +############################################################################## |
| 4 | +# |
| 5 | +# diffpy.pdfmorph by DANSE Diffraction group |
| 6 | +# Simon J. L. Billinge |
| 7 | +# (c) 2010 Trustees of the Columbia University |
| 8 | +# in the City of New York. All rights reserved. |
| 9 | +# |
| 10 | +# File coded by: Andrew Yang |
| 11 | +# |
| 12 | +# See AUTHORS.txt for a list of people who contributed. |
| 13 | +# See LICENSE.txt for license information. |
| 14 | +# |
| 15 | +############################################################################## |
| 16 | + |
| 17 | +from diffpy.pdfmorph.pdfmorphapp import create_option_parser, multiple_morphs, multiple_targets, single_morph |
| 18 | + |
| 19 | + |
| 20 | +def pdfmorph(file1, file2, **kwargs): |
| 21 | + """Run PDFmorph at Python level. |
| 22 | +
|
| 23 | + Parameters |
| 24 | + ---------- |
| 25 | + file1: str |
| 26 | + Path-like object to the file to be morphed. |
| 27 | + file2: str |
| 28 | + Path-like object to the target file. |
| 29 | + kwargs: dict |
| 30 | + See the PDFmorph manual for options. |
| 31 | +
|
| 32 | + Returns |
| 33 | + ------- |
| 34 | + dict: |
| 35 | + Summary of morphs. |
| 36 | + """ |
| 37 | + |
| 38 | + parser = create_option_parser() |
| 39 | + |
| 40 | + inputs = [] |
| 41 | + for key, value in kwargs.items(): |
| 42 | + inputs.append(f"--{key}") |
| 43 | + inputs.append(f"{value}") |
| 44 | + (opts, pargs) = parser.parse_args(inputs) |
| 45 | + pargs = [file1, file2] |
| 46 | + |
| 47 | + return single_morph(parser, opts, pargs) |
| 48 | + |
| 49 | + |
| 50 | +def pdfmorph_multiple_targets(file, dir, **kwargs): |
| 51 | + """Run PDFmorph with multiple targets at Python level. |
| 52 | +
|
| 53 | + Parameters |
| 54 | + ---------- |
| 55 | + file1: str |
| 56 | + Path-like object to the file to be morphed. |
| 57 | + file2: str |
| 58 | + Path-like object to the target file. |
| 59 | + kwargs: dict |
| 60 | + See the PDFmorph manual for options. |
| 61 | +
|
| 62 | + Returns |
| 63 | + ------- |
| 64 | + dict: |
| 65 | + Summary of morphs. |
| 66 | + """ |
| 67 | + |
| 68 | + parser = create_option_parser() |
| 69 | + |
| 70 | + inputs = [] |
| 71 | + for key, value in kwargs.items(): |
| 72 | + inputs.append(f"--{key}") |
| 73 | + inputs.append(f"{value}") |
| 74 | + (opts, pargs) = parser.parse_args(inputs) |
| 75 | + pargs = [file, dir] |
| 76 | + |
| 77 | + return multiple_targets(parser, opts, pargs) |
| 78 | + |
| 79 | + |
| 80 | +def pdfmorph_multiple_morphs(dir, file, **kwargs): |
| 81 | + """Run PDFmorph for multiple morphs at Python level. |
| 82 | +
|
| 83 | + Parameters |
| 84 | + ---------- |
| 85 | + file1: str |
| 86 | + Path-like object to the file to be morphed. |
| 87 | + file2: str |
| 88 | + Path-like object to the target file. |
| 89 | + kwargs: dict |
| 90 | + See the PDFmorph manual for options. |
| 91 | +
|
| 92 | + Returns |
| 93 | + ------- |
| 94 | + dict: |
| 95 | + Summary of morphs. |
| 96 | + """ |
| 97 | + |
| 98 | + parser = create_option_parser() |
| 99 | + |
| 100 | + inputs = [] |
| 101 | + for key, value in kwargs.items(): |
| 102 | + inputs.append(f"--{key}") |
| 103 | + inputs.append(f"{value}") |
| 104 | + (opts, pargs) = parser.parse_args(inputs) |
| 105 | + pargs = [dir, file] |
| 106 | + |
| 107 | + return multiple_morphs(parser, opts, pargs) |
0 commit comments