psdi-data-conversion 0.2.2__py3-none-any.whl → 0.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- psdi_data_conversion/app.py +1 -1
- psdi_data_conversion/converters/openbabel.py +82 -11
- psdi_data_conversion/database.py +39 -14
- psdi_data_conversion/main.py +29 -38
- psdi_data_conversion/utils.py +19 -0
- {psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/METADATA +52 -11
- {psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/RECORD +10 -10
- {psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/WHEEL +0 -0
- {psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/entry_points.txt +0 -0
- {psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/licenses/LICENSE +0 -0
psdi_data_conversion/app.py
CHANGED
@@ -10,7 +10,7 @@ from argparse import ArgumentParser
|
|
10
10
|
from psdi_data_conversion import constants as const
|
11
11
|
from psdi_data_conversion.gui.env import update_env
|
12
12
|
from psdi_data_conversion.gui.setup import get_app, limit_upload_size, start_app
|
13
|
-
from psdi_data_conversion.
|
13
|
+
from psdi_data_conversion.utils import print_wrap
|
14
14
|
|
15
15
|
app = get_app()
|
16
16
|
|
@@ -12,6 +12,7 @@ from openbabel import openbabel
|
|
12
12
|
|
13
13
|
from psdi_data_conversion.converters.base import FileConverter, FileConverterInputException
|
14
14
|
from psdi_data_conversion.security import SAFE_STRING_RE, string_is_safe
|
15
|
+
from psdi_data_conversion.utils import print_wrap
|
15
16
|
|
16
17
|
CONVERTER_OB = 'Open Babel'
|
17
18
|
|
@@ -83,30 +84,34 @@ class OBFileConverter(FileConverter):
|
|
83
84
|
`run_converter()` through providing a dict to the `data` kwarg. The supported keys and values are:
|
84
85
|
|
85
86
|
"from_flags": str
|
86
|
-
String of concatenated one-letter flags for how to
|
87
|
-
|
88
|
-
|
87
|
+
String of concatenated one-letter flags for how to write the output file, e.g. ``"from_flags": "xyz"`` will set
|
88
|
+
flags x, y and z. To list the flags supported for a given output format, call
|
89
|
+
``psdi-data-convert -l -f <format> -w Open Babel`` at the command-line and look for the "Allowed input flags"
|
90
|
+
section, if one exists, or alternatively call the library function
|
89
91
|
``psdi_data_conversion.database.get_in_format_args("Open Babel", <format>)`` from within Python code.
|
90
92
|
|
91
93
|
"to_flags": str
|
92
|
-
String of concatenated one-letter flags for how to write the output file.
|
93
|
-
|
94
|
-
|
94
|
+
String of concatenated one-letter flags for how to write the output file, e.g. ``"to_flags": "xyz"`` will set
|
95
|
+
flags x, y and z. To list the flags supported for a given output format, call
|
96
|
+
``psdi-data-convert -l -t <format> -w Open Babel`` at the command-line and look for the "Allowed output flags"
|
97
|
+
section, if one exists, or alternatively call the library function
|
95
98
|
``psdi_data_conversion.database.get_out_format_args("Open Babel", <format>)`` from within Python code.
|
96
99
|
|
97
100
|
"from_options": str
|
98
101
|
String of space-separated options for how to read the input file. Each option "word" in this string should start
|
99
|
-
with the letter indicating which option is being used, followed by the value for that option.
|
102
|
+
with the letter indicating which option is being used, followed by the value for that option. E.g.
|
103
|
+
``"from_options": "a1 b2"`` will set the value 1 for option a and the value 2 for option b. To list the
|
100
104
|
options supported for a given input format, call ``psdi-data-convert -l -f <format> -w Open Babel`` at the
|
101
105
|
command-line and look for the "Allowed input options" section, if one exists, or alternatively call the library
|
102
106
|
function ``psdi_data_conversion.database.get_in_format_args("Open Babel", <format>)`` from within Python code.
|
103
107
|
|
104
108
|
"to_options": str
|
105
109
|
String of space-separated options for how to write the output file. Each option "word" in this string should
|
106
|
-
start with the letter indicating which option is being used, followed by the value for that option.
|
110
|
+
start with the letter indicating which option is being used, followed by the value for that option. E.g.
|
111
|
+
``"to_options": "a1 b2"`` will set the value 1 for option a and the value 2 for option b. To list the
|
107
112
|
options supported for a given output format, call ``psdi-data-convert -l -t <format> -w Open Babel`` at the
|
108
113
|
command-line and look for the "Allowed output options" section, if one exists, or alternatively call the library
|
109
|
-
function ``psdi_data_conversion.database.
|
114
|
+
function ``psdi_data_conversion.database.get_in_format_args("Open Babel", <format>)`` from within Python code.
|
110
115
|
|
111
116
|
"coordinates": str
|
112
117
|
One of "Gen2D", "Gen3D", or "neither", specifying how positional coordinates should be generated in the output
|
@@ -159,13 +164,28 @@ class OBFileConverter(FileConverter):
|
|
159
164
|
from_args = self.data.get("from_args", "")
|
160
165
|
to_args = self.data.get("to_args", "")
|
161
166
|
|
167
|
+
from psdi_data_conversion.database import (FileConverterDatabaseException, get_in_format_args,
|
168
|
+
get_out_format_args)
|
169
|
+
|
162
170
|
# Add option flags and arguments as appropriate
|
163
171
|
for char in from_flags:
|
164
172
|
check_string_security(char)
|
173
|
+
# Check that the flag is valid
|
174
|
+
try:
|
175
|
+
get_in_format_args(self.name, self.from_format_info, char)
|
176
|
+
except FileConverterDatabaseException:
|
177
|
+
print_wrap(f"WARNING: Input format flag '{char}' not recognised for conversion with {self.name}. "
|
178
|
+
"If this is valid, the database should be updated to indicate this.", err=True)
|
165
179
|
ob_conversion.AddOption(char, ob_conversion.INOPTIONS)
|
166
180
|
|
167
181
|
for char in to_flags:
|
168
182
|
check_string_security(char)
|
183
|
+
# Check that the flag is valid
|
184
|
+
try:
|
185
|
+
get_out_format_args(self.name, self.from_format_info, char)
|
186
|
+
except FileConverterDatabaseException:
|
187
|
+
print_wrap(f"WARNING: Output format flag '{char}' not recognised for conversion with {self.name}. "
|
188
|
+
"If this is valid, the database should be updated to indicate this", err=True)
|
169
189
|
ob_conversion.AddOption(char, ob_conversion.OUTOPTIONS)
|
170
190
|
|
171
191
|
self.data["read_flags_args"] = []
|
@@ -176,37 +196,82 @@ class OBFileConverter(FileConverter):
|
|
176
196
|
if "from_options" in self.data:
|
177
197
|
# From options were provided by the command-line script or library
|
178
198
|
l_from_options = self.data["from_options"].split()
|
199
|
+
|
179
200
|
for opt in l_from_options:
|
180
201
|
option, value = get_option_and_value(opt)
|
202
|
+
|
203
|
+
# Check that the option is valid
|
204
|
+
try:
|
205
|
+
get_in_format_args(self.name, self.from_format_info, option)
|
206
|
+
except FileConverterDatabaseException:
|
207
|
+
print_wrap(f"WARNING: Input format option '{option}' not recognised for conversion with "
|
208
|
+
f"{self.name}. If this is valid, the database should be updated to indicate "
|
209
|
+
"this", err=True)
|
210
|
+
|
181
211
|
ob_conversion.AddOption(option, ob_conversion.INOPTIONS, value)
|
212
|
+
|
182
213
|
self.logger.debug(f"Set Open Babel read flags arguments to: {self.data['from_options']}")
|
183
214
|
# Store the options in the "read_flags_args" entry for the later logging
|
184
215
|
self.data["read_flags_args"] = l_from_options
|
216
|
+
|
185
217
|
else:
|
186
218
|
# From options were provided by the command-line script or library
|
187
219
|
for char in from_arg_flags:
|
220
|
+
|
188
221
|
index = from_args.find('£')
|
189
222
|
arg, from_args = from_args[0:index], from_args[index + 1:len(from_args)]
|
190
223
|
check_string_security(char), check_string_security(arg)
|
224
|
+
|
225
|
+
# Check that the option is valid
|
226
|
+
try:
|
227
|
+
get_in_format_args(self.name, self.from_format_info, arg)
|
228
|
+
except FileConverterDatabaseException:
|
229
|
+
print_wrap(f"WARNING: Input format option '{arg}' not recognised for conversion with "
|
230
|
+
f"{self.name}. If this is valid, the database should be updated to indicate "
|
231
|
+
"this.", err=True)
|
232
|
+
|
191
233
|
ob_conversion.AddOption(char, ob_conversion.INOPTIONS, arg)
|
192
234
|
self.data["read_flags_args"].append(char + " " + arg)
|
235
|
+
|
193
236
|
self.logger.debug(f"Set Open Babel read flags arguments to: {self.data['read_flags_args']}")
|
194
237
|
|
195
238
|
if "to_options" in self.data:
|
196
239
|
# From options were provided by the command-line script or library
|
197
240
|
l_to_options = self.data["to_options"].split()
|
241
|
+
|
198
242
|
for opt in l_to_options:
|
199
243
|
option, value = get_option_and_value(opt)
|
244
|
+
|
245
|
+
# Check that the option is valid
|
246
|
+
try:
|
247
|
+
get_out_format_args(self.name, self.to_format_info, option)
|
248
|
+
except FileConverterDatabaseException:
|
249
|
+
print_wrap(f"WARNING: Output format option '{option}' not recognised for conversion with "
|
250
|
+
f"{self.name}. If this is valid, the database should be updated to indicate "
|
251
|
+
"this.", err=True)
|
252
|
+
|
200
253
|
ob_conversion.AddOption(option, ob_conversion.OUTOPTIONS, value)
|
254
|
+
|
201
255
|
self.logger.debug(f"Set Open Babel write flags arguments to: {self.data['to_options']}")
|
202
256
|
# Store the options in the "write_flags_args" entry for the later logging
|
203
257
|
self.data["write_flags_args"] = l_to_options
|
258
|
+
|
204
259
|
else:
|
205
|
-
#
|
260
|
+
# To options were provided by the command-line script or library
|
206
261
|
for char in to_arg_flags:
|
262
|
+
|
207
263
|
index = to_args.find('£')
|
208
264
|
arg, to_args = to_args[0:index], to_args[index + 1:len(to_args)]
|
209
265
|
check_string_security(char), check_string_security(arg)
|
266
|
+
|
267
|
+
# Check that the option is valid
|
268
|
+
try:
|
269
|
+
get_out_format_args(self.name, self.to_format_info, arg)
|
270
|
+
except FileConverterDatabaseException:
|
271
|
+
print_wrap(f"WARNING: Output format option '{arg}' not recognised for conversion with "
|
272
|
+
f"{self.name}. If this is valid, the database should be updated to indicate "
|
273
|
+
"this.", err=True)
|
274
|
+
|
210
275
|
ob_conversion.AddOption(char, ob_conversion.OUTOPTIONS, arg)
|
211
276
|
self.data["write_flags_args"].append(char + " " + arg)
|
212
277
|
self.logger.debug(f"Set Open Babel write flags arguments to: {self.data['read_flags_args']}")
|
@@ -239,6 +304,12 @@ class OBFileConverter(FileConverter):
|
|
239
304
|
if "Open Babel Error" in self.err:
|
240
305
|
self._abort_from_err()
|
241
306
|
|
307
|
+
# Check for any non-critical errors and print them out
|
308
|
+
l_err_blocks = self.err.split("\n\n")
|
309
|
+
for err_block in l_err_blocks:
|
310
|
+
if err_block.startswith("ERROR:") or err_block.startswith("WARNING:"):
|
311
|
+
print_wrap(err_block, err=True)
|
312
|
+
|
242
313
|
def _create_message(self) -> str:
|
243
314
|
"""Overload method to create a log of options passed to the converter
|
244
315
|
"""
|
@@ -248,7 +319,7 @@ class OBFileConverter(FileConverter):
|
|
248
319
|
label_length = 19
|
249
320
|
|
250
321
|
for (label, key, multi) in (("Coord. gen.:", COORD_GEN_KEY, False),
|
251
|
-
("Coord. option:",
|
322
|
+
("Coord. option:", COORD_GEN_QUAL_KEY, False),
|
252
323
|
("Read options:", "from_flags", False),
|
253
324
|
("Write options:", "to_flags", False),
|
254
325
|
("Read opts + args:", "read_flags_args", True),
|
psdi_data_conversion/database.py
CHANGED
@@ -383,47 +383,69 @@ class ConverterInfo:
|
|
383
383
|
self._d_out_format_options = self._create_d_format_args(OptionInfo, "out")
|
384
384
|
return self._d_out_format_options
|
385
385
|
|
386
|
-
def get_in_format_args(self,
|
386
|
+
def get_in_format_args(self, in_format: str | int | FormatInfo) -> tuple[list[FlagInfo], list[OptionInfo]]:
|
387
387
|
"""Get the input flags and options supported for a given format (provided as its extension)
|
388
388
|
|
389
389
|
Parameters
|
390
390
|
----------
|
391
|
-
|
392
|
-
The file format name (extension)
|
391
|
+
in_format : str
|
392
|
+
The file format name (extension), ID, or FormatInfo
|
393
393
|
|
394
394
|
Returns
|
395
395
|
-------
|
396
396
|
tuple[set[FlagInfo], set[OptionInfo]]
|
397
397
|
A set of info for the allowed flags, and a set of info for the allowed options
|
398
398
|
"""
|
399
|
-
|
399
|
+
|
400
|
+
l_in_format_infos = get_format_info(in_format, which="all")
|
401
|
+
s_flag_ids = set()
|
402
|
+
s_option_ids = set()
|
403
|
+
|
404
|
+
for in_format_info in l_in_format_infos:
|
405
|
+
in_format_id = in_format_info.id
|
406
|
+
|
407
|
+
s_flag_ids.update(self.d_in_format_flags.get(in_format_id, set()))
|
408
|
+
s_option_ids.update(self.d_in_format_options.get(in_format_id, set()))
|
409
|
+
|
410
|
+
l_flag_ids = list(s_flag_ids)
|
400
411
|
l_flag_ids.sort()
|
401
412
|
l_flag_info = [self.l_in_flag_info[x] for x in l_flag_ids]
|
402
413
|
|
403
|
-
l_option_ids = list(
|
414
|
+
l_option_ids = list(s_option_ids)
|
404
415
|
l_option_ids.sort()
|
405
416
|
l_option_info = [self.l_in_option_info[x] for x in l_option_ids]
|
406
417
|
|
407
418
|
return l_flag_info, l_option_info
|
408
419
|
|
409
|
-
def get_out_format_args(self,
|
420
|
+
def get_out_format_args(self, out_format: str | int | FormatInfo) -> tuple[list[FlagInfo], list[OptionInfo]]:
|
410
421
|
"""Get the output flags and options supported for a given format (provided as its extension)
|
411
422
|
|
412
423
|
Parameters
|
413
424
|
----------
|
414
|
-
|
415
|
-
The file format name (extension)
|
425
|
+
out_format : str
|
426
|
+
The file format name (extension), ID, or FormatInfo
|
416
427
|
|
417
428
|
Returns
|
418
429
|
-------
|
419
430
|
tuple[set[FlagInfo], set[OptionInfo]]
|
420
431
|
A set of info for the allowed flags, and a set of info for the allowed options
|
421
432
|
"""
|
422
|
-
|
433
|
+
|
434
|
+
l_out_format_infos = get_format_info(out_format, which="all")
|
435
|
+
s_flag_ids = set()
|
436
|
+
s_option_ids = set()
|
437
|
+
|
438
|
+
for out_format_info in l_out_format_infos:
|
439
|
+
out_format_id = out_format_info.id
|
440
|
+
|
441
|
+
s_flag_ids.update(self.d_out_format_flags.get(out_format_id, set()))
|
442
|
+
s_option_ids.update(self.d_out_format_options.get(out_format_id, set()))
|
443
|
+
|
444
|
+
l_flag_ids = list(s_flag_ids)
|
423
445
|
l_flag_ids.sort()
|
424
446
|
l_flag_info = [self.l_out_flag_info[x] for x in l_flag_ids]
|
425
447
|
|
426
|
-
l_option_ids = list(
|
448
|
+
l_option_ids = list(s_option_ids)
|
427
449
|
l_option_ids.sort()
|
428
450
|
l_option_info = [self.l_out_option_info[x] for x in l_option_ids]
|
429
451
|
|
@@ -1430,11 +1452,14 @@ def disambiguate_formats(converter_name: str,
|
|
1430
1452
|
raise FileConverterDatabaseException(f"Conversion from {in_format} to {out_format} with converter "
|
1431
1453
|
f"{converter_name} is not supported", help=True)
|
1432
1454
|
else:
|
1433
|
-
msg = (f"Conversion from {in_format} to {out_format} with converter {converter_name} is ambiguous
|
1434
|
-
"Possible matching
|
1455
|
+
msg = (f"Conversion from {in_format} to {out_format} with converter {converter_name} is ambiguous. Please "
|
1456
|
+
"Use the ID or disambiguated name (listed below) of the desired conversion. Possible matching "
|
1457
|
+
"conversions are:\n")
|
1435
1458
|
for _, possible_in_format, possible_out_format in l_possible_conversions:
|
1436
|
-
msg += (f"{possible_in_format.
|
1437
|
-
f"
|
1459
|
+
msg += (f" {possible_in_format.id}: {possible_in_format.disambiguated_name} "
|
1460
|
+
f"({possible_in_format.note}) to "
|
1461
|
+
f"{possible_out_format.id}: {possible_out_format.disambiguated_name} "
|
1462
|
+
f"({possible_out_format.note})\n")
|
1438
1463
|
# Trim the final newline from the message
|
1439
1464
|
msg = msg[:-1]
|
1440
1465
|
raise FileConverterDatabaseException(msg, help=True)
|
psdi_data_conversion/main.py
CHANGED
@@ -26,20 +26,7 @@ from psdi_data_conversion.database import (FormatInfo, get_conversion_pathway, g
|
|
26
26
|
get_out_format_args, get_possible_conversions, get_possible_formats)
|
27
27
|
from psdi_data_conversion.file_io import split_archive_ext
|
28
28
|
from psdi_data_conversion.log_utility import get_log_level_from_str
|
29
|
-
from psdi_data_conversion.utils import regularize_name
|
30
|
-
|
31
|
-
|
32
|
-
def print_wrap(s: str, newline=False, err=False, **kwargs):
|
33
|
-
"""Print a string wrapped to the terminal width
|
34
|
-
"""
|
35
|
-
if err:
|
36
|
-
file = sys.stderr
|
37
|
-
else:
|
38
|
-
file = sys.stdout
|
39
|
-
for line in s.split("\n"):
|
40
|
-
print(textwrap.fill(line, width=TERM_WIDTH, **kwargs), file=file)
|
41
|
-
if newline:
|
42
|
-
print("")
|
29
|
+
from psdi_data_conversion.utils import print_wrap, regularize_name
|
43
30
|
|
44
31
|
|
45
32
|
class ConvertArgs:
|
@@ -260,29 +247,29 @@ def get_argument_parser():
|
|
260
247
|
parser.add_argument("--delete-input", action="store_true",
|
261
248
|
help="If set, input files will be deleted after conversion, default they will be kept")
|
262
249
|
parser.add_argument("--from-flags", type=str, default="",
|
263
|
-
help="
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
"be backslash-escaped, e.g. '--from-flags \"\\-a \\-bc \\--example\"'")
|
250
|
+
help="String of concatenated one-letter flags for how to read the input file, e.g. "
|
251
|
+
"``--from-flags xyz`` will set flags x, y, and z. To list the flags supported for a given "
|
252
|
+
"input format, call ``psdi-data-convert -l -f <format> -w Open Babel`` at the command-line "
|
253
|
+
"and look for the \"Allowed input flags\" section, if one exists.")
|
268
254
|
parser.add_argument("--to-flags", type=str, default="",
|
269
|
-
help="
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
"be backslash-escaped, e.g. '--to-flags \"\\-a \\-bc \\--example\"'")
|
255
|
+
help="String of concatenated one-letter flags for how to write the output file, e.g. "
|
256
|
+
"``--from-flags xyz`` will set flags x, y, and z. To list the flags supported for a given "
|
257
|
+
"output format, call ``psdi-data-convert -l -t <format> -w Open Babel`` at the command-line "
|
258
|
+
"and look for the \"Allowed output flags\" section, if one exists.")
|
274
259
|
parser.add_argument("--from-options", type=str, default="",
|
275
|
-
help="
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
260
|
+
help="String of space-separated options for how to read the input file. Each option \"word\" "
|
261
|
+
"in this string should start with the letter indicating which option is being used, followed "
|
262
|
+
"by the value for that option. E.g. ``--from_options a1 b2`` will set the value 1 for "
|
263
|
+
"option a and the value 2 for option b. To list the options supported for a given input "
|
264
|
+
"format, call ``psdi-data-convert -l -f <format> -w Open Babel`` at the command-line and look "
|
265
|
+
"for the \"Allowed input options\" section, if one exists.")
|
280
266
|
parser.add_argument("--to-options", type=str, default="",
|
281
|
-
help="
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
267
|
+
help="String of space-separated options for how to write the output file. Each option \"word\" "
|
268
|
+
"in this string should start with the letter indicating which option is being used, followed "
|
269
|
+
"by the value for that option. E.g. ``--to_options a1 b2`` will set the value 1 for "
|
270
|
+
"option a and the value 2 for option b. To list the options supported for a given output "
|
271
|
+
"format, call ``psdi-data-convert -l -t <format> -w Open Babel`` at the command-line and look "
|
272
|
+
"for the \"Allowed input options\" section, if one exists.")
|
286
273
|
parser.add_argument("-s", "--strict", action="store_true",
|
287
274
|
help="If set, will fail if one of the input files has the wrong extension (including those "
|
288
275
|
"contained in archives, but not the archive files themselves). Otherwise, will only print a "
|
@@ -399,13 +386,17 @@ def detail_converter_use(args: ConvertArgs):
|
|
399
386
|
|
400
387
|
print_wrap(f"File formats supported by {converter_name}:", newline=True)
|
401
388
|
max_format_length = max([len(x.disambiguated_name) for x in l_all_formats])
|
402
|
-
print(" "*(max_format_length+4) + "
|
403
|
-
print(" "*(max_format_length+4) + "
|
389
|
+
print(" "*(max_format_length+4) + " INPUT OUTPUT DESCRIPTION")
|
390
|
+
print(" "*(max_format_length+4) + " ----- ------ -----------")
|
404
391
|
for file_format in l_all_formats:
|
405
392
|
in_yes_or_no = "yes" if file_format in l_input_formats else "no"
|
406
393
|
out_yes_or_no = "yes" if file_format in l_output_formats else "no"
|
407
|
-
print(f" {file_format.disambiguated_name:>{max_format_length}}{in_yes_or_no
|
408
|
-
|
394
|
+
print(f" {file_format.disambiguated_name:>{max_format_length}} {in_yes_or_no:<9}{out_yes_or_no:<10}"
|
395
|
+
f"{file_format.note}")
|
396
|
+
print_wrap("\nFor more information on a format, including its ID (which can be used to specify it uniquely in "
|
397
|
+
"case of ambiguity, and is resilient to database changes affecting the disambiguated names listed "
|
398
|
+
"above), call:\n"
|
399
|
+
f"{CL_SCRIPT_NAME} -l -f <format>", newline=True)
|
409
400
|
|
410
401
|
if converter_class.allowed_flags is None:
|
411
402
|
print_wrap("Information has not been provided about general flags accepted by this converter.", newline=True)
|
psdi_data_conversion/utils.py
CHANGED
@@ -5,6 +5,25 @@ Miscellaneous utility functions used by this project
|
|
5
5
|
"""
|
6
6
|
|
7
7
|
|
8
|
+
import sys
|
9
|
+
import textwrap
|
10
|
+
|
11
|
+
from psdi_data_conversion.constants import TERM_WIDTH
|
12
|
+
|
13
|
+
|
14
|
+
def print_wrap(s: str, newline=False, err=False, **kwargs):
|
15
|
+
"""Print a string wrapped to the terminal width
|
16
|
+
"""
|
17
|
+
if err:
|
18
|
+
file = sys.stderr
|
19
|
+
else:
|
20
|
+
file = sys.stdout
|
21
|
+
for line in s.split("\n"):
|
22
|
+
print(textwrap.fill(line, width=TERM_WIDTH, **kwargs), file=file)
|
23
|
+
if newline:
|
24
|
+
print("")
|
25
|
+
|
26
|
+
|
8
27
|
def regularize_name(name: str):
|
9
28
|
"""Regularizes a name for comparisons, making it lowercase and stripping spaces
|
10
29
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: psdi_data_conversion
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.4
|
4
4
|
Summary: Chemistry file format conversion service, provided by PSDI
|
5
5
|
Project-URL: Homepage, https://data-conversion.psdi.ac.uk/
|
6
6
|
Project-URL: Documentation, https://psdi-uk.github.io/psdi-data-conversion/
|
@@ -293,6 +293,7 @@ This is the repository for the PSDI PF2 Chemistry File Format Conversion project
|
|
293
293
|
- [Input file is malformatted or corrupt](#input-file-is-malformatted-or-corrupt)
|
294
294
|
- [Input file's format is misidentified](#input-files-format-is-misidentified)
|
295
295
|
- [Other known issues](#other-known-issues)
|
296
|
+
- [Feedback](#feedback)
|
296
297
|
- [Licensing](#licensing)
|
297
298
|
- [Contributors](#contributors)
|
298
299
|
- [Funding](#funding)
|
@@ -484,12 +485,17 @@ options] [-s/--strict] [--nc/--no-check] [-q/--quiet] [-g/--log-file <log file n
|
|
484
485
|
|
485
486
|
Call `psdi-data-convert -h` for details on each of these options.
|
486
487
|
|
487
|
-
Note that some requested conversions may involve ambiguous formats which share the same extension. In this case, the application will print a warning and list possible matching formats, with
|
488
|
+
Note that some requested conversions may involve ambiguous formats which share the same extension. In this case, the application will print a warning and list possible matching formats, with IDs and disambiguating names that can be used to specify which one. For instance, the `c2x` converter can convert into two variants of the `pdb` format, and if you ask it to convert to `pdb` without specifying which one, you'll see:
|
488
489
|
|
489
490
|
```
|
490
|
-
|
491
|
+
WARNING: Format 'pdb' is ambiguous and could refer to multiple formats. It may be necessary to explicitly specify which
|
492
|
+
you want to use when calling this script, e.g. with '-f pdb-0' - see the disambiguated names in the list below:
|
493
|
+
|
491
494
|
9: pdb-0 (Protein Data Bank)
|
495
|
+
...
|
496
|
+
|
492
497
|
259: pdb-1 (Protein Data Bank with atoms numbered)
|
498
|
+
...
|
493
499
|
```
|
494
500
|
|
495
501
|
This provides the IDs ("9" and "259") and disambiguating names ("pdb-0" and "pdb-1") for the matching formats. Either can be used in the call to the converter, e.g.:
|
@@ -745,38 +751,69 @@ To remedy this, try explicitly specifying the format, rather than letting the ap
|
|
745
751
|
`<format>` here can be the standard extension of the format (in the case of unambiguous extensions), its ID, or its disambiguated name. To give an example which explains what each of these are, let's say you have an MDL MOL file you wish to convert to XYZ, so you get information about it and possible converters with `psdi-data-convert -l -f mol -t xyz`:
|
746
752
|
|
747
753
|
```base
|
748
|
-
$ psdi-data-convert -l -f mol
|
754
|
+
$ psdi-data-convert -l -f mol -t xyz
|
749
755
|
WARNING: Format 'mol' is ambiguous and could refer to multiple formats. It may be necessary to explicitly specify which
|
750
756
|
you want to use when calling this script, e.g. with '-f mol-0' - see the disambiguated names in the list below:
|
751
757
|
|
752
758
|
18: mol-0 (MDL MOL)
|
759
|
+
- Atomic composition is supported
|
760
|
+
- Atomic connections are supported
|
761
|
+
- 2D atomic coordinates are supported
|
762
|
+
- 3D atomic coordinates are supported
|
763
|
+
|
753
764
|
216: mol-1 (MOLDY)
|
765
|
+
- Atomic composition is unknown whether or not to be supported
|
766
|
+
- Atomic connections are unknown whether or not to be supported
|
767
|
+
- 2D atomic coordinates are unknown whether or not to be supported
|
768
|
+
- 3D atomic coordinates are unknown whether or not to be supported
|
769
|
+
|
770
|
+
WARNING: Format 'xyz' is ambiguous and could refer to multiple formats. It may be necessary to explicitly specify which
|
771
|
+
you want to use when calling this script, e.g. with '-f xyz-0' - see the disambiguated names in the list below:
|
754
772
|
|
755
|
-
20: xyz (XYZ cartesian coordinates)
|
773
|
+
20: xyz-0 (XYZ cartesian coordinates)
|
774
|
+
- Atomic composition is supported
|
775
|
+
- Atomic connections are not supported
|
776
|
+
- 2D atomic coordinates are supported
|
777
|
+
- 3D atomic coordinates are supported
|
756
778
|
|
757
|
-
|
779
|
+
284: xyz-1 (Extended XYZ (adds lattice vectors))
|
780
|
+
- Atomic composition is unknown whether or not to be supported
|
781
|
+
- Atomic connections are unknown whether or not to be supported
|
782
|
+
- 2D atomic coordinates are unknown whether or not to be supported
|
783
|
+
- 3D atomic coordinates are unknown whether or not to be supported
|
784
|
+
|
785
|
+
The following registered converters can convert from mol-0 to xyz-0:
|
758
786
|
|
759
787
|
Open Babel
|
760
788
|
c2x
|
761
789
|
|
762
790
|
For details on input/output flags and options allowed by a converter for this conversion, call:
|
763
|
-
psdi-data-convert -l <converter name> -f mol-0 -t xyz
|
791
|
+
psdi-data-convert -l <converter name> -f mol-0 -t xyz-0
|
792
|
+
|
793
|
+
The following registered converters can convert from mol-0 to xyz-1:
|
764
794
|
|
765
|
-
|
795
|
+
c2x
|
796
|
+
|
797
|
+
For details on input/output flags and options allowed by a converter for this conversion, call:
|
798
|
+
psdi-data-convert -l <converter name> -f mol-0 -t xyz-1
|
799
|
+
|
800
|
+
The following registered converters can convert from mol-1 to xyz-0:
|
766
801
|
|
767
802
|
Atomsk
|
768
803
|
|
769
804
|
For details on input/output flags and options allowed by a converter for this conversion, call:
|
770
|
-
psdi-data-convert -l <converter name> -f mol-1 -t xyz
|
805
|
+
psdi-data-convert -l <converter name> -f mol-1 -t xyz-0
|
806
|
+
|
807
|
+
No converters are available which can perform a conversion from mol-1 to xyz-1
|
771
808
|
```
|
772
809
|
|
773
|
-
This output indicates that the application is aware of two formats which share the `mol` extension: MDL MOL and MOLDY. It lists the ID, disambiguated name, and description of each: ID `18` and disambiguated name `mol-0` for MDL MOL, and ID `216` and disambiguated name `mol-1` for MOLDY. The XYZ format
|
810
|
+
This output indicates that the application is aware of two formats which share the `mol` extension: MDL MOL and MOLDY. It lists the ID, disambiguated name, and description of each: ID `18` and disambiguated name `mol-0` for MDL MOL, and ID `216` and disambiguated name `mol-1` for MOLDY. The XYZ format similarly has two variants which can be converted to.
|
774
811
|
|
775
812
|
The program then lists converters which can handle the requested conversion, revealing a potential pitfall: The Open Babel and c2x converters can convert from MDL MOL to XYZ, which the Atomsk converter can convert from MOLDY to XYZ. If you don't specify which format you're converting from, the script might assume you meant to use the other one, if that's the only one compatible with the converter you've requested (or with the default converter, Open Babel, if you didn't explicitly request one). So to be careful here, it's best to specify this input format unambiguously.
|
776
813
|
|
777
814
|
Since in this example you have an MDL MOL file, you would use `-f 18` or `-f mol-0` to explicitly specify it in the command-line, or similarly provide one of these to the `from_format` argument of `run_converter` within Python. The application will then properly handle it, including alerting you if you request a conversion that isn't supported by your requested converter (e.g. if you request a conversion of this MDL MOL file to XYZ with Atomsk).
|
778
815
|
|
779
|
-
Important note: The disambiguated name is generated dynamically and isn't stored in the database, and in rare cases may change for some formats in future versions of this application which expand support to more formats and conversions. For uses which require forward-compatibility with future versions of this application, the ID should be used instead.
|
816
|
+
Important note: The disambiguated name is generated dynamically and isn't stored in the database, and in rare cases may change for some formats in future versions of this application which expand support to more formats and conversions. For uses which require forward-compatibility with future versions of this application, the ID should be used instead. You can obtain the ID for any format via the command: `psdi-data-convert -l -f <format-name>`.
|
780
817
|
|
781
818
|
#### Other known issues
|
782
819
|
|
@@ -784,6 +821,10 @@ Through testing, we've identified some other conversion issues, which we list he
|
|
784
821
|
|
785
822
|
- Open Babel will indefinitely hang when attempting to convert large files (more than ~1 MB) of certain types (such as `mmcif`). This is an issue with the converter itself and not our application, which we hope will be fixed in a future version. If this occurs, the job will have to be forcibly terminated. CTRL+C will fail to terminate it, but it can be stopped with CTRL+Z, then terminated with `kill %N`, where N is the number listed beside the job when it is stopped (usually 1). The conversion should then be attempted with another supported converter.
|
786
823
|
|
824
|
+
## Feedback
|
825
|
+
|
826
|
+
To report a missing format or conversion, please use [the form on the public web service](https://data-conversion.psdi.ac.uk/report.htm). Other feedback can be submitted on [the feedback page](https://data-conversion.psdi.ac.uk/static/content/feedback.htm).
|
827
|
+
|
787
828
|
## Licensing
|
788
829
|
|
789
830
|
This project is provided under the Apache License version 2.0, the terms of which can be found in the file `LICENSE`.
|
@@ -1,14 +1,14 @@
|
|
1
1
|
psdi_data_conversion/__init__.py,sha256=urMsTqsTHTch1q4rMT9dgGnrvdPFMP9B8r-6Kr8H5sE,404
|
2
|
-
psdi_data_conversion/app.py,sha256=
|
2
|
+
psdi_data_conversion/app.py,sha256=u26a6taxmS3Yn9o78hL1avpO-50BnbcMnJAuVn5XlEc,3607
|
3
3
|
psdi_data_conversion/constants.py,sha256=eXE43_9YFahoehiUV7FtqN9MKb-UpSfY2win9ic9W8I,7348
|
4
4
|
psdi_data_conversion/converter.py,sha256=OlwGKxI8nj76wrlVzP5S7fpXb6L-Ql8-mYLYGhW81Fk,27816
|
5
|
-
psdi_data_conversion/database.py,sha256=
|
5
|
+
psdi_data_conversion/database.py,sha256=dJudFtSAXy814Ymw8ht9Lzfs4v-A6hv5k2busaXJlKU,66524
|
6
6
|
psdi_data_conversion/dist.py,sha256=Db7mbLLANfugaptrcWCoVddwHT2rdP4X4HuP6uxr9AI,2309
|
7
7
|
psdi_data_conversion/file_io.py,sha256=SE7cXVedm5ZLdxDQ7W7L2R9LXTqJz2Tak9-YTvc7_js,9250
|
8
8
|
psdi_data_conversion/log_utility.py,sha256=CHAq-JvBnTKaE0SHK5hM5j2dTbfSli4iUc3hsf6dBhc,8789
|
9
|
-
psdi_data_conversion/main.py,sha256=
|
9
|
+
psdi_data_conversion/main.py,sha256=_HmlDicG7TD7-taLNPazZS4rflXUU7ijHv3Tzx5kyLM,44770
|
10
10
|
psdi_data_conversion/security.py,sha256=wjdrMre29TpkF2NqrsXJ5sschSAnDzqLYTLUcNR21Qw,902
|
11
|
-
psdi_data_conversion/utils.py,sha256=
|
11
|
+
psdi_data_conversion/utils.py,sha256=1DaTxoaUkoiImBYyXIiPToV2ae2eZEDPxbNWUvEqwDg,821
|
12
12
|
psdi_data_conversion/bin/LICENSE_ATOMSK,sha256=-Ay6SFTAf9x-OaRAiOgMNoutfUMLHx5jQQA1HqZ6p7I,34886
|
13
13
|
psdi_data_conversion/bin/LICENSE_C2X,sha256=-Ay6SFTAf9x-OaRAiOgMNoutfUMLHx5jQQA1HqZ6p7I,34886
|
14
14
|
psdi_data_conversion/bin/linux/atomsk,sha256=GDsG1MlEvmk_XPspadzEzuil6N775iewDvNZS6rWJWk,34104032
|
@@ -19,7 +19,7 @@ psdi_data_conversion/converters/__init__.py,sha256=15Ldt06eyZ0bgNPB4qg419U0Zcjt6
|
|
19
19
|
psdi_data_conversion/converters/atomsk.py,sha256=_V33me1e4HW0-YXvdE-z6PdwtSK2gYV6QZf5d8aPqH4,1523
|
20
20
|
psdi_data_conversion/converters/base.py,sha256=yGlwQmYcLSKP9DH2reTBGvJ-HhfxjO_dYo6qVX501Zw,36515
|
21
21
|
psdi_data_conversion/converters/c2x.py,sha256=jDA84H8Jpz--ajTWNWX6K6oMfOMMbMxkA31-VnGi0gU,2019
|
22
|
-
psdi_data_conversion/converters/openbabel.py,sha256=
|
22
|
+
psdi_data_conversion/converters/openbabel.py,sha256=2S3WZcYpS-FhKv2lqYndTWn-FNh8LeX3-Kc1nGw0y7s,16957
|
23
23
|
psdi_data_conversion/gui/__init__.py,sha256=Q52GAaJWfNWGDOAEM_fIfAoivLIgM3krhVTiHFTRixM,125
|
24
24
|
psdi_data_conversion/gui/accessibility.py,sha256=XQyAAJZQdIyRftfidhhVgsZXVtA9b9qZhwwFm899kbE,1302
|
25
25
|
psdi_data_conversion/gui/env.py,sha256=nVuKzuE6z9ItH09ZRkooGRUTVZSHtPzSR9XrZVDHC-0,9235
|
@@ -87,8 +87,8 @@ psdi_data_conversion/testing/conversion_callbacks.py,sha256=ATR-_BsYCUN8KyOyUjfd
|
|
87
87
|
psdi_data_conversion/testing/conversion_test_specs.py,sha256=PFzTZYonQ0PsZBKjcn0Hp-UPbwphT3zRH5v-VdNImmQ,27585
|
88
88
|
psdi_data_conversion/testing/gui.py,sha256=ul7ixYANIzmOG2ZNOZmQO6wsHmGHdiBGAlw-KuoN0j8,19085
|
89
89
|
psdi_data_conversion/testing/utils.py,sha256=uhJQUceaNmpQd3SioFLZVMExMVzO3Ds8V9DD2hqP-mQ,26700
|
90
|
-
psdi_data_conversion-0.2.
|
91
|
-
psdi_data_conversion-0.2.
|
92
|
-
psdi_data_conversion-0.2.
|
93
|
-
psdi_data_conversion-0.2.
|
94
|
-
psdi_data_conversion-0.2.
|
90
|
+
psdi_data_conversion-0.2.4.dist-info/METADATA,sha256=hlT0b9qN26H0fVAnNI7euuBjKKVl_VUR1SLAdAzJtBg,50396
|
91
|
+
psdi_data_conversion-0.2.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
92
|
+
psdi_data_conversion-0.2.4.dist-info/entry_points.txt,sha256=xL7XTzaPRr2E67WhOD1M1Q-76hB8ausQlnNiHzuZQPA,123
|
93
|
+
psdi_data_conversion-0.2.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
94
|
+
psdi_data_conversion-0.2.4.dist-info/RECORD,,
|
File without changes
|
{psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/entry_points.txt
RENAMED
File without changes
|
{psdi_data_conversion-0.2.2.dist-info → psdi_data_conversion-0.2.4.dist-info}/licenses/LICENSE
RENAMED
File without changes
|