py2opsin 1.2.0__tar.gz → 1.3.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py2opsin
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: Simple Python interface to OPSIN: Open Parser for Systematic IUPAC nomenclature
5
5
  Home-page: https://github.com/JacksonBurns/py2opsin
6
6
  Author: Jackson Burns, Jonathan Zheng
@@ -43,7 +43,7 @@ Dynamic: summary
43
43
  </p>
44
44
 
45
45
  ## Installation
46
- `py2opsin` can be installed with `pip install py2opsin`. It has _zero_ Python dependencies (`OPSIN v2.9.0` is included in the PyPI package) and should work inside any environment running modern Python. Java 8+ is required to run OPSIN.
46
+ `py2opsin` can be installed with `pip install py2opsin`. It has _zero_ Python dependencies (`OPSIN v2.10.0` is included in the PyPI package) and should work inside any environment running modern Python. Java 8+ is required to run OPSIN.
47
47
 
48
48
  Try a demo of `py2opsin` live on your browser (no installation required!): [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JacksonBurns/py2opsin/blob/main/examples/py2opsin_example.ipynb)
49
49
 
@@ -66,6 +66,7 @@ smiles_str = "CC"
66
66
  allow_radicals = True,
67
67
  allow_bad_stereo = False,
68
68
  wildcard_radicals = False,
69
+ threads = 1,
69
70
  jar_fpath = "/path/to/opsin.jar",
70
71
  tmp_fpath = "py2opsin_temp_input.txt",
71
72
  )
@@ -80,8 +81,9 @@ Arguments:
80
81
  - allow_radicals (bool, optional): Enable radical interpretation. Defaults to False.
81
82
  - allow_bad_stereo (bool, optional): Allow OPSIN to ignore uninterpreatable stereochem. Defaults to False.
82
83
  - wildcard_radicals (bool, optional): Output radicals as wildcards. Defaults to False.
83
- - jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "opsin-cli.jar" which is distributed with py2opsin.
84
- - tmp_fpath (str, optional): tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt". When multiprocessing, set this to a unique name for each process.
84
+ - threads (int, optional): Number of names to interpret concurrently (`OPSIN >= 2.10.0`). Output order always matches input order. Use `0` for one thread per available processor. Defaults to 1 (sequential).
85
+ - jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "default", which uses the jar distributed with py2opsin.
86
+ - tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt". When multiprocessing, set this to a unique name for each process.
85
87
 
86
88
  ## Massive speedup from `pubchempy` for batch translations
87
89
  `py2opsin` runs locally and is smaller in scope in what it provides, which makes it __dramatically__ faster at resolving identifiers. In the code block below, the call to `py2opsin` will execute faster than an equivalent call to `pubchempy`:
@@ -14,7 +14,7 @@
14
14
  </p>
15
15
 
16
16
  ## Installation
17
- `py2opsin` can be installed with `pip install py2opsin`. It has _zero_ Python dependencies (`OPSIN v2.9.0` is included in the PyPI package) and should work inside any environment running modern Python. Java 8+ is required to run OPSIN.
17
+ `py2opsin` can be installed with `pip install py2opsin`. It has _zero_ Python dependencies (`OPSIN v2.10.0` is included in the PyPI package) and should work inside any environment running modern Python. Java 8+ is required to run OPSIN.
18
18
 
19
19
  Try a demo of `py2opsin` live on your browser (no installation required!): [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JacksonBurns/py2opsin/blob/main/examples/py2opsin_example.ipynb)
20
20
 
@@ -37,6 +37,7 @@ smiles_str = "CC"
37
37
  allow_radicals = True,
38
38
  allow_bad_stereo = False,
39
39
  wildcard_radicals = False,
40
+ threads = 1,
40
41
  jar_fpath = "/path/to/opsin.jar",
41
42
  tmp_fpath = "py2opsin_temp_input.txt",
42
43
  )
@@ -51,8 +52,9 @@ Arguments:
51
52
  - allow_radicals (bool, optional): Enable radical interpretation. Defaults to False.
52
53
  - allow_bad_stereo (bool, optional): Allow OPSIN to ignore uninterpreatable stereochem. Defaults to False.
53
54
  - wildcard_radicals (bool, optional): Output radicals as wildcards. Defaults to False.
54
- - jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "opsin-cli.jar" which is distributed with py2opsin.
55
- - tmp_fpath (str, optional): tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt". When multiprocessing, set this to a unique name for each process.
55
+ - threads (int, optional): Number of names to interpret concurrently (`OPSIN >= 2.10.0`). Output order always matches input order. Use `0` for one thread per available processor. Defaults to 1 (sequential).
56
+ - jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "default", which uses the jar distributed with py2opsin.
57
+ - tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt". When multiprocessing, set this to a unique name for each process.
56
58
 
57
59
  ## Massive speedup from `pubchempy` for batch translations
58
60
  `py2opsin` runs locally and is smaller in scope in what it provides, which makes it __dramatically__ faster at resolving identifiers. In the code block below, the call to `py2opsin` will execute faster than an equivalent call to `pubchempy`:
@@ -1,3 +1,3 @@
1
1
  from .py2opsin import py2opsin
2
2
 
3
- __version__ = "1.2.0"
3
+ __version__ = "1.3.0"
@@ -51,6 +51,7 @@ def py2opsin(
51
51
  allow_radicals: bool = False,
52
52
  allow_bad_stereo: bool = False,
53
53
  wildcard_radicals: bool = False,
54
+ threads: int = 1,
54
55
  jar_fpath: str = "default",
55
56
  tmp_fpath: str = "py2opsin_temp_input.txt",
56
57
  ) -> str:
@@ -64,6 +65,9 @@ def py2opsin(
64
65
  allow_radicals (bool, optional): Enable radical interpretation. Defaults to False.
65
66
  allow_bad_stereo (bool, optional): Allow OPSIN to ignore uninterpreatable stereochem. Defaults to False.
66
67
  wildcard_radicals (bool, optional): Output radicals as wildcards. Defaults to False.
68
+ threads (int, optional): Number of names to interpret concurrently (OPSIN >= 2.10.0).
69
+ Output order always matches input order. Use 0 for one thread
70
+ per available processor. Defaults to 1 (sequential).
67
71
  jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "default", which causes py2opsin to use its included jar.
68
72
  tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt".
69
73
  When multiprocessing, set this to a unique name for each process.
@@ -73,7 +77,7 @@ def py2opsin(
73
77
  """
74
78
  # path to OPSIN jar
75
79
  if jar_fpath == "default":
76
- jar_fpath = pkg_fopen("opsin-cli-2.9.0-jar-with-dependencies.jar")
80
+ jar_fpath = pkg_fopen("opsin-cli-2.10.0-jar-with-dependencies.jar")
77
81
 
78
82
  # default arguments to start
79
83
  arg_list = ["java", "-jar", jar_fpath]
@@ -132,6 +136,13 @@ def py2opsin(
132
136
  arg_list.append("-s")
133
137
  if wildcard_radicals:
134
138
  arg_list.append("-w")
139
+ if not isinstance(threads, int) or isinstance(threads, bool) or threads < 0:
140
+ raise RuntimeError(
141
+ "threads must be a non-negative integer (0 = one thread per "
142
+ "available processor), got {!r}.".format(threads)
143
+ )
144
+ if threads != 1:
145
+ arg_list.extend(["-t", str(threads)])
135
146
 
136
147
  # do the call
137
148
  result = subprocess.run(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py2opsin
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: Simple Python interface to OPSIN: Open Parser for Systematic IUPAC nomenclature
5
5
  Home-page: https://github.com/JacksonBurns/py2opsin
6
6
  Author: Jackson Burns, Jonathan Zheng
@@ -43,7 +43,7 @@ Dynamic: summary
43
43
  </p>
44
44
 
45
45
  ## Installation
46
- `py2opsin` can be installed with `pip install py2opsin`. It has _zero_ Python dependencies (`OPSIN v2.9.0` is included in the PyPI package) and should work inside any environment running modern Python. Java 8+ is required to run OPSIN.
46
+ `py2opsin` can be installed with `pip install py2opsin`. It has _zero_ Python dependencies (`OPSIN v2.10.0` is included in the PyPI package) and should work inside any environment running modern Python. Java 8+ is required to run OPSIN.
47
47
 
48
48
  Try a demo of `py2opsin` live on your browser (no installation required!): [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JacksonBurns/py2opsin/blob/main/examples/py2opsin_example.ipynb)
49
49
 
@@ -66,6 +66,7 @@ smiles_str = "CC"
66
66
  allow_radicals = True,
67
67
  allow_bad_stereo = False,
68
68
  wildcard_radicals = False,
69
+ threads = 1,
69
70
  jar_fpath = "/path/to/opsin.jar",
70
71
  tmp_fpath = "py2opsin_temp_input.txt",
71
72
  )
@@ -80,8 +81,9 @@ Arguments:
80
81
  - allow_radicals (bool, optional): Enable radical interpretation. Defaults to False.
81
82
  - allow_bad_stereo (bool, optional): Allow OPSIN to ignore uninterpreatable stereochem. Defaults to False.
82
83
  - wildcard_radicals (bool, optional): Output radicals as wildcards. Defaults to False.
83
- - jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "opsin-cli.jar" which is distributed with py2opsin.
84
- - tmp_fpath (str, optional): tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt". When multiprocessing, set this to a unique name for each process.
84
+ - threads (int, optional): Number of names to interpret concurrently (`OPSIN >= 2.10.0`). Output order always matches input order. Use `0` for one thread per available processor. Defaults to 1 (sequential).
85
+ - jar_fpath (str, optional): Filepath to OPSIN jar file. Defaults to "default", which uses the jar distributed with py2opsin.
86
+ - tmp_fpath (str, optional): Name for temporary file used for calling OPSIN. Defaults to "py2opsin_temp_input.txt". When multiprocessing, set this to a unique name for each process.
85
87
 
86
88
  ## Massive speedup from `pubchempy` for batch translations
87
89
  `py2opsin` runs locally and is smaller in scope in what it provides, which makes it __dramatically__ faster at resolving identifiers. In the code block below, the call to `py2opsin` will execute faster than an equivalent call to `pubchempy`:
@@ -3,7 +3,7 @@ MANIFEST.in
3
3
  README.md
4
4
  setup.py
5
5
  py2opsin/__init__.py
6
- py2opsin/opsin-cli-2.9.0-jar-with-dependencies.jar
6
+ py2opsin/opsin-cli-2.10.0-jar-with-dependencies.jar
7
7
  py2opsin/py2opsin.py
8
8
  py2opsin.egg-info/PKG-INFO
9
9
  py2opsin.egg-info/SOURCES.txt
@@ -1,5 +1,5 @@
1
- import os
2
1
  import multiprocessing
2
+ import os
3
3
  import sys
4
4
  import unittest
5
5
 
@@ -18,11 +18,6 @@ class Test_py2opsin(unittest.TestCase):
18
18
 
19
19
  @classmethod
20
20
  def setUpClass(self):
21
- self.jar_path = os.path.join(
22
- os.getcwd(),
23
- "opsin-cli-2.7.0-jar-with-dependencies.jar",
24
- )
25
-
26
21
  self.chemical_names = (
27
22
  "ethane",
28
23
  "water",
@@ -204,6 +199,44 @@ class Test_py2opsin(unittest.TestCase):
204
199
  smiles_list = py2opsin(list_with_errors)
205
200
  self.assertEqual(smiles_list, correct_list)
206
201
 
202
+ def test_threads_matches_sequential(self):
203
+ """
204
+ Multi-threaded interpretation (OPSIN -t flag) must return the same
205
+ results, in the same order, as sequential interpretation.
206
+ """
207
+ sequential = py2opsin(self.chemical_names)
208
+ threaded = py2opsin(self.chemical_names, threads=4)
209
+ self.assertEqual(threaded, sequential)
210
+ self.assertEqual(threaded, list(self.chemical_smiles))
211
+
212
+ def test_threads_zero(self):
213
+ """
214
+ threads=0 should use one thread per available processor and work.
215
+ """
216
+ result = py2opsin(self.chemical_names, threads=0)
217
+ self.assertEqual(result, list(self.chemical_smiles))
218
+
219
+ def test_threads_single_string(self):
220
+ """
221
+ threads should be a no-op (not an error) for a single input name.
222
+ """
223
+ self.assertEqual(py2opsin("ethane", threads=4), "CC")
224
+
225
+ def test_threads_with_format_and_flags(self):
226
+ """
227
+ threads should compose with other options.
228
+ """
229
+ threaded = py2opsin(self.chemical_names, output_format="StdInChIKey", threads=2)
230
+ self.assertEqual(threaded, list(self.chemical_stdinchikeys))
231
+
232
+ def test_threads_invalid(self):
233
+ """
234
+ Invalid thread counts should raise a helpful RuntimeError.
235
+ """
236
+ for bad in [-1, 1.5, "4", True]:
237
+ with self.assertRaises(RuntimeError):
238
+ py2opsin(self.chemical_names, threads=bad)
239
+
207
240
 
208
241
  if __name__ == "__main__":
209
242
  unittest.main()
File without changes
File without changes
File without changes
File without changes