rowan-python 1.1.2__py3-none-any.whl → 1.1.5__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.
@@ -1,5 +1,5 @@
1
1
  from .chem_utils import (run_pka, run_tautomers, run_conformers, run_energy,
2
- run_optimize, run_batch_pka, run_batch_tautomers, run_batch_energy, run_batch_optimize, run_batch_conformers)
2
+ run_optimize, batch_pka, batch_tautomers, batch_energy, batch_optimize, batch_conformers, run_charges, batch_charges)
3
3
 
4
4
  __all__ = ["run_pka", "run_tautomers", "run_energy", "run_conformers", "run_optimize",
5
- "run_batch_pka", "run_batch_tautomers", "run_batch_energy", "run_batch_optimize", "run_batch_conformers"]
5
+ "batch_pka", "batch_tautomers", "batch_energy", "batch_optimize", "batch_conformers", "run_charges", "batch_charges"]
@@ -5,7 +5,6 @@ import rowan
5
5
  import copy
6
6
  import asyncio
7
7
  import logging
8
- import math
9
8
  from rowan.utils import get_api_key
10
9
  import stjames
11
10
  import time
@@ -91,7 +90,7 @@ def run_pka(mol: RdkitMol,
91
90
  folder_uuid: Optional[stjames.UUID] = None)-> tuple[dict[int, float], dict[int, float]]:
92
91
  return asyncio.run(_single_pka(mol, mode, timeout, name, pka_range, deprotonate_elements, protonate_elements, folder_uuid))
93
92
 
94
- def run_batch_pka(mols: List[RdkitMol],
93
+ def batch_pka(mols: List[RdkitMol],
95
94
  mode: pKaMode = "rapid",
96
95
  timeout: int = 600,
97
96
  name: str = "pKa API Workflow",
@@ -99,14 +98,14 @@ def run_batch_pka(mols: List[RdkitMol],
99
98
  deprotonate_elements: list[int] = [7, 8, 16],
100
99
  protonate_elements: list[int] = [7],
101
100
  folder_uuid: Optional[stjames.UUID] = None)-> tuple[dict[int, float], dict[int, float]]:
102
- loop = asyncio.new_event_loop()
103
- asyncio.set_event_loop(loop)
104
- tasks = [
105
- _single_pka(mol, mode, timeout, name, pka_range, deprotonate_elements, protonate_elements, folder_uuid)
106
- for mol in mols
107
- ]
108
- results = loop.run_until_complete(asyncio.gather(*tasks))
109
- return results
101
+ async def _run():
102
+ tasks = [
103
+ _single_pka(mol, mode, timeout, name, pka_range,
104
+ deprotonate_elements, protonate_elements, folder_uuid)
105
+ for mol in mols
106
+ ]
107
+ return await asyncio.gather(*tasks)
108
+ return asyncio.run(_run())
110
109
 
111
110
 
112
111
  async def _single_pka(mol: RdkitMol,
@@ -180,7 +179,7 @@ def run_tautomers(mol: RdkitMol,
180
179
  """
181
180
  return asyncio.run(_single_tautomers(mol, mode, timeout, name, folder_uuid))
182
181
 
183
- def run_batch_tautomers(mols: List[RdkitMol],
182
+ def batch_tautomers(mols: List[RdkitMol],
184
183
  mode: TautomerMode = "reckless",
185
184
  timeout: int = 600,
186
185
  name: str = "Tautomers API Workflow",
@@ -190,11 +189,13 @@ def run_batch_tautomers(mols: List[RdkitMol],
190
189
  :param mol: RDKit molecule object
191
190
  :return: A list of lists of tautomer dictionaries which include the RDKit molecule object, the relative energy, and the weight
192
191
  """
193
- loop = asyncio.new_event_loop()
194
- asyncio.set_event_loop(loop)
195
- tasks = [_single_tautomers(mol, mode, timeout, name, folder_uuid) for mol in mols]
196
- results = loop.run_until_complete(asyncio.gather(*tasks))
197
- return results
192
+ async def _run():
193
+ tasks = [
194
+ _single_tautomers(mol, mode, timeout, name, folder_uuid)
195
+ for mol in mols
196
+ ]
197
+ return await asyncio.gather(*tasks)
198
+ return asyncio.run(_run())
198
199
 
199
200
 
200
201
  async def _single_tautomers(mol: RdkitMol,
@@ -257,7 +258,7 @@ def run_energy(
257
258
  """
258
259
  return asyncio.run(_single_energy(mol, method, engine, mode, timeout, name, folder_uuid))
259
260
 
260
- def run_batch_energy(
261
+ def batch_energy(
261
262
  mols: List[RdkitMol],
262
263
  method: str = "aimnet2_wb97md3",
263
264
  engine: str = "aimnet2",
@@ -274,11 +275,13 @@ def run_batch_energy(
274
275
  :raises: MethodTooSlowError if the method is invalid
275
276
  :returns: a list of dictionaries with the energy in Hartree and the conformer index
276
277
  """
277
- loop = asyncio.new_event_loop()
278
- asyncio.set_event_loop(loop)
279
- tasks = [_single_energy(mol, method, engine, mode, timeout, name, folder_uuid) for mol in mols]
280
- results = loop.run_until_complete(asyncio.gather(*tasks))
281
- return results
278
+ async def _run():
279
+ tasks = [
280
+ _single_energy(mol, method, engine, mode, timeout, name, folder_uuid)
281
+ for mol in mols
282
+ ]
283
+ return await asyncio.gather(*tasks)
284
+ return asyncio.run(_run())
282
285
 
283
286
  async def _single_energy(
284
287
  mol: RdkitMol,
@@ -373,7 +376,7 @@ def run_optimize(
373
376
  """
374
377
  return asyncio.run(_single_optimize(mol, method, engine, mode, return_energies, timeout, name, folder_uuid))
375
378
 
376
- def run_batch_optimize(
379
+ def batch_optimize(
377
380
  mols: List[RdkitMol],
378
381
  method: str = "aimnet2_wb97md3",
379
382
  engine: str = "aimnet2",
@@ -393,11 +396,13 @@ def run_batch_optimize(
393
396
  :returns: a list of dictionaries with the molecule, with optimized conformers, and optionally a list of energies per conformer too
394
397
 
395
398
  """
396
- loop = asyncio.new_event_loop()
397
- asyncio.set_event_loop(loop)
398
- tasks = [_single_optimize(mol, method, engine, mode, return_energies, timeout, name, folder_uuid) for mol in mols]
399
- results = loop.run_until_complete(asyncio.gather(*tasks))
400
- return results
399
+ async def _run():
400
+ tasks = [
401
+ _single_optimize(mol, method, engine, mode, return_energies, timeout, name, folder_uuid)
402
+ for mol in mols
403
+ ]
404
+ return await asyncio.gather(*tasks)
405
+ return asyncio.run(_run())
401
406
 
402
407
  async def _single_optimize(
403
408
  mol: RdkitMol,
@@ -501,7 +506,7 @@ def run_conformers(mol: RdkitMol, num_conformers=10,
501
506
  """
502
507
  return asyncio.run(_single_conformers(mol, num_conformers, method, mode, return_energies, timeout, name, folder_uuid))
503
508
 
504
- def run_batch_conformers(mols: List[RdkitMol], num_conformers=10,
509
+ def batch_conformers(mols: List[RdkitMol], num_conformers=10,
505
510
  method: str = "aimnet2_wb97md3",
506
511
  mode: str = "rapid",
507
512
  return_energies: bool = False,
@@ -514,11 +519,13 @@ def run_batch_conformers(mols: List[RdkitMol], num_conformers=10,
514
519
  :param num_conformers: Number of conformers to generate
515
520
  :return: A list of dictonaries with the RDKit molecule with num_conformers lowest energy conformers and optional energies
516
521
  """
517
- loop = asyncio.new_event_loop()
518
- asyncio.set_event_loop(loop)
519
- tasks = [_single_conformers(mol, num_conformers, method, mode, return_energies, timeout, name, folder_uuid) for mol in mols]
520
- results = loop.run_until_complete(asyncio.gather(*tasks))
521
- return results
522
+ async def _run():
523
+ tasks = [
524
+ _single_conformers(mol, num_conformers, method, mode, return_energies, timeout, name, folder_uuid)
525
+ for mol in mols
526
+ ]
527
+ return await asyncio.gather(*tasks)
528
+ return asyncio.run(_run())
522
529
 
523
530
 
524
531
  async def _single_conformers(mol: RdkitMol, num_conformers=10,
@@ -608,3 +615,121 @@ async def _single_conformers(mol: RdkitMol, num_conformers=10,
608
615
  return_dict["energies"] = lowest_energies
609
616
 
610
617
  return return_dict
618
+
619
+ def run_charges(
620
+ mol: RdkitMol,
621
+ method: str = "aimnet2_wb97md3",
622
+ engine: str = "aimnet2",
623
+ mode: str = "auto",
624
+ timeout: int = 600,
625
+ name: str = "Charges API Workflow",
626
+ folder_uuid: Optional[stjames.UUID] = None
627
+ ):
628
+ """
629
+ Computes atom-centered charges for the given molecule.
630
+
631
+ :param mol: the input molecule
632
+ :param method: the method with which to compute the molecule's energy
633
+ :raises: MethodTooSlowError if the method is invalid
634
+ :returns: a dictionary with the charges and the conformer index
635
+ """
636
+ return asyncio.run(_single_charges(mol, method, engine, mode, timeout, name, folder_uuid))
637
+
638
+ def batch_charges(
639
+ mols: List[RdkitMol],
640
+ method: str = "aimnet2_wb97md3",
641
+ engine: str = "aimnet2",
642
+ mode: str = "auto",
643
+ timeout: int = 600,
644
+ name: str = "Charges API Workflow",
645
+ folder_uuid: Optional[stjames.UUID] = None
646
+ ):
647
+ """
648
+ Computes the energy for the given molecule.
649
+
650
+ :param mol: the input molecule
651
+ :param method: the method with which to compute the molecule's energy
652
+ :raises: MethodTooSlowError if the method is invalid
653
+ :returns: a list of dictionaries with the charges and the conformer index
654
+ """
655
+ async def _run():
656
+ tasks = [
657
+ _single_charges(mol, method, engine, mode, timeout, name, folder_uuid)
658
+ for mol in mols
659
+ ]
660
+ return await asyncio.gather(*tasks)
661
+ return asyncio.run(_run())
662
+
663
+ async def _single_charges(
664
+ mol: RdkitMol,
665
+ method: str = "aimnet2_wb97md3",
666
+ engine: str = "aimnet2",
667
+ mode: str = "auto",
668
+ timeout: int = 600,
669
+ name: str = "Energy API Workflow",
670
+ folder_uuid: Optional[stjames.UUID] = None
671
+ ):
672
+ """
673
+ Computes the energy for the given molecule.
674
+
675
+ :param mol: the input molecule
676
+ :param method: the method with which to compute the molecule's energy
677
+ :param engine: the engine
678
+ :param mode:
679
+ :param timeout: the timeout in seconds
680
+ :raises: MethodTooSlowError if the method is invalid
681
+ :returns: a dictionary with the charges and the conformer index
682
+ """
683
+ get_api_key()
684
+
685
+ method = stjames.Method(method)
686
+
687
+ if mol.GetNumConformers() == 0:
688
+ mol = _embed_rdkit_mol(mol)
689
+ if mol.GetNumConformers() == 0:
690
+ raise NoConformersError("This molecule has no conformers")
691
+
692
+ if method not in FAST_METHODS:
693
+ raise MethodTooSlowError(
694
+ "This method is too slow; try running this through our web interface."
695
+ )
696
+
697
+ workflow_uuids = []
698
+ for conformer in mol.GetConformers():
699
+ cid = conformer.GetId()
700
+ stjames_mol = _rdkit_to_stjames(mol, cid)
701
+ get_api_key()
702
+ post = rowan.Workflow.submit(
703
+ name=name,
704
+ workflow_type="basic_calculation",
705
+ initial_molecule=stjames_mol,
706
+ workflow_data={
707
+ "settings": {
708
+ "method": method.value,
709
+ "corrections": [],
710
+ "tasks": [
711
+ "charge"
712
+ ],
713
+ "mode": mode,
714
+ "opt_settings": {
715
+ "constraints": []
716
+ }
717
+ },
718
+ "engine": engine
719
+ },
720
+ folder_uuid=folder_uuid
721
+ )
722
+
723
+ workflow_uuids.append(post["uuid"])
724
+
725
+ start = time.time()
726
+ while not all(rowan.Workflow.is_finished(uuid) for uuid in workflow_uuids):
727
+ await asyncio.sleep(5)
728
+ if time.time() - start > timeout:
729
+ raise TimeoutError("Workflow timed out")
730
+
731
+ workflow_results = [rowan.Workflow.retrieve(uuid) for uuid in workflow_uuids]
732
+ charges_list = [rowan.Calculation.retrieve(workflow["object_data"]["calculation_uuid"])["molecules"][-1]["mulliken_charges"] for workflow in workflow_results]
733
+
734
+ return [{"conformer_index": index, "charges": charges} for index, charges in enumerate(charges_list)]
735
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rowan-python
3
- Version: 1.1.2
3
+ Version: 1.1.5
4
4
  Summary: Rowan Python Library
5
5
  Project-URL: Homepage, https://github.com/rowansci/rowan-client
6
6
  Project-URL: Bug Tracker, https://github.com/rowansci/rowan-client/issues
@@ -5,9 +5,9 @@ rowan/constants.py,sha256=ZZvv3L0b2y3dMGlWGeaRmx40J5tBrpxNxvJgjP1TNjg,37
5
5
  rowan/folder.py,sha256=W7-YnPxugqzIdw-t1sr-WjeSQa-x4IjZ2mV2DwIq3II,2965
6
6
  rowan/utils.py,sha256=IMACnRJpjFns_DF-FZQDu8p8fbgu4C2dbDaxdGcSZQs,1405
7
7
  rowan/workflow.py,sha256=An3CW9LlHxYByE4mRl1iYThYcIGry8TwTi5rgbAsEBc,4467
8
- rowan/rowan_rdkit/__init__.py,sha256=BfKNC7Ts_Gay-A6FzElwg8UM4fxSapCLzeKwr7_HZNs,395
9
- rowan/rowan_rdkit/chem_utils.py,sha256=mVBE_OPGSPwEX_nhsJ43fIBAbdiQMTvYVHEQ9gCf0-M,22493
10
- rowan_python-1.1.2.dist-info/METADATA,sha256=u7oIN6zws1JHthPcb8l818KoLcXFSYXsXxyeRbq7wO8,1030
11
- rowan_python-1.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
- rowan_python-1.1.2.dist-info/licenses/LICENSE,sha256=i7ehYBS-6gGmbTcgU4mgk28pyOx2kScJ0kcx8n7bWLM,1084
13
- rowan_python-1.1.2.dist-info/RECORD,,
8
+ rowan/rowan_rdkit/__init__.py,sha256=AGoN4fbsSbKGfeke4bPvEfgeBAM4PaasAPIILonIeBU,415
9
+ rowan/rowan_rdkit/chem_utils.py,sha256=nbvOAEKfCStiaSi-NpxqU5C9BQrLwTMNWtd7v9DpkYw,26360
10
+ rowan_python-1.1.5.dist-info/METADATA,sha256=2GNrC93mhprXn0HipCO_3k5lbdsmbLFwYTM8uga_X0I,1030
11
+ rowan_python-1.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ rowan_python-1.1.5.dist-info/licenses/LICENSE,sha256=i7ehYBS-6gGmbTcgU4mgk28pyOx2kScJ0kcx8n7bWLM,1084
13
+ rowan_python-1.1.5.dist-info/RECORD,,