sapiopycommons 2025.7.9a582__py3-none-any.whl → 2025.7.9a583__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.

Potentially problematic release.


This version of sapiopycommons might be problematic. Click here for more details.

Files changed (59) hide show
  1. sapiopycommons/callbacks/callback_util.py +665 -332
  2. sapiopycommons/callbacks/field_builder.py +2 -0
  3. sapiopycommons/chem/IndigoMolecules.py +29 -1
  4. sapiopycommons/chem/Molecules.py +3 -3
  5. sapiopycommons/customreport/auto_pagers.py +26 -1
  6. sapiopycommons/customreport/term_builder.py +1 -1
  7. sapiopycommons/datatype/pseudo_data_types.py +349 -326
  8. sapiopycommons/eln/experiment_cache.py +188 -0
  9. sapiopycommons/eln/experiment_handler.py +408 -767
  10. sapiopycommons/eln/experiment_report_util.py +11 -6
  11. sapiopycommons/eln/experiment_step_factory.py +476 -0
  12. sapiopycommons/eln/plate_designer.py +7 -2
  13. sapiopycommons/eln/step_creation.py +236 -0
  14. sapiopycommons/files/file_util.py +7 -5
  15. sapiopycommons/general/accession_service.py +2 -2
  16. sapiopycommons/general/aliases.py +3 -1
  17. sapiopycommons/general/audit_log.py +7 -0
  18. sapiopycommons/general/custom_report_util.py +12 -0
  19. sapiopycommons/general/data_structure_util.py +115 -0
  20. sapiopycommons/processtracking/custom_workflow_handler.py +11 -1
  21. sapiopycommons/processtracking/endpoints.py +27 -0
  22. sapiopycommons/recordmodel/record_handler.py +783 -389
  23. sapiopycommons/rules/eln_rule_handler.py +8 -1
  24. sapiopycommons/rules/on_save_rule_handler.py +8 -1
  25. sapiopycommons/webhook/webhook_handlers.py +9 -4
  26. sapiopycommons/webhook/webservice_handlers.py +2 -2
  27. {sapiopycommons-2025.7.9a582.dist-info → sapiopycommons-2025.7.9a583.dist-info}/METADATA +2 -2
  28. sapiopycommons-2025.7.9a583.dist-info/RECORD +68 -0
  29. sapiopycommons/ai/__init__.py +0 -0
  30. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py +0 -43
  31. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi +0 -31
  32. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py +0 -24
  33. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +0 -123
  34. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +0 -598
  35. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +0 -24
  36. sapiopycommons/ai/api/plan/proto/step_output_pb2.py +0 -45
  37. sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +0 -42
  38. sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +0 -24
  39. sapiopycommons/ai/api/plan/proto/step_pb2.py +0 -43
  40. sapiopycommons/ai/api/plan/proto/step_pb2.pyi +0 -43
  41. sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +0 -24
  42. sapiopycommons/ai/api/plan/script/proto/script_pb2.py +0 -55
  43. sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +0 -115
  44. sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +0 -153
  45. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +0 -57
  46. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +0 -96
  47. sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +0 -24
  48. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +0 -67
  49. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +0 -220
  50. sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +0 -154
  51. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +0 -39
  52. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +0 -32
  53. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +0 -24
  54. sapiopycommons/ai/protobuf_utils.py +0 -508
  55. sapiopycommons/ai/test_client.py +0 -251
  56. sapiopycommons/ai/tool_service_base.py +0 -798
  57. sapiopycommons-2025.7.9a582.dist-info/RECORD +0 -92
  58. {sapiopycommons-2025.7.9a582.dist-info → sapiopycommons-2025.7.9a583.dist-info}/WHEEL +0 -0
  59. {sapiopycommons-2025.7.9a582.dist-info → sapiopycommons-2025.7.9a583.dist-info}/licenses/LICENSE +0 -0
@@ -443,6 +443,8 @@ class FieldBuilder:
443
443
  raise SapioException("Unable to set multiple list modes at once for a selection list.")
444
444
  # Static values don't have a list mode. Evaluate this last so that the multiple list modes check doesn't
445
445
  # need to be more complex.
446
+ # PR-47531: Even though static values don't use an existing list mode, a list mode must still be set.
447
+ list_mode = ListMode.USER
446
448
 
447
449
  if not list_mode and static_values is None:
448
450
  raise SapioException("A list mode must be chosen for selection list fields.")
@@ -10,9 +10,36 @@ indigo.setOption("render-stereo-style", "ext")
10
10
  indigo.setOption("aromaticity-model", "generic")
11
11
  indigo.setOption("render-coloring", True)
12
12
  indigo.setOption("molfile-saving-mode", "3000")
13
+ indigo.setOption("dearomatize-verification", False)
13
14
  indigo_inchi = IndigoInchi(indigo)
14
15
 
15
16
 
17
+ def get_aromatic_dearomatic_forms(m: IndigoObject):
18
+ """
19
+ Get the aromatic and dearomatic forms of the molecule. Retain the original form if it's not inversible.
20
+ Inversible: after aromatic-dearomatic-aromatic transformation, the molecule is the same as the first aromatic transformation.
21
+ :param m: molecule from indigo.
22
+ :return: pair of indigo objects, first is aromatic, second is dearomatic.
23
+ """
24
+ try:
25
+ aromatic_reaction = m.clone()
26
+ aromatic_reaction.aromatize()
27
+ dearomatic_reaction = aromatic_reaction.clone()
28
+ dearomatic_reaction.dearomatize()
29
+ second_aromatic_reaction = dearomatic_reaction.clone()
30
+ second_aromatic_reaction.aromatize()
31
+ match = indigo.exactMatch(aromatic_reaction, second_aromatic_reaction)
32
+ if match:
33
+ return aromatic_reaction, dearomatic_reaction
34
+ else:
35
+ return m, dearomatic_reaction
36
+ except (Exception):
37
+ # If aromatization then following deromatization fails, we just skip it.
38
+ dearomatic_reaction = m.clone()
39
+ dearomatic_reaction.dearomatize()
40
+ return m, dearomatic_reaction
41
+
42
+
16
43
  # Function to process dative bonds in a molecule
17
44
  # Returns True if at least one dative bond (_BOND_COORDINATION) was removed
18
45
  def remove_dative_bonds_in_mol(molecule: IndigoObject) -> bool:
@@ -51,7 +78,8 @@ def remove_dative_in_reaction(reaction: IndigoObject) -> bool:
51
78
  :param reaction: The reaction to remove dative bonds.
52
79
  :return: Whether there are any dative bonds in the reaction that were removed.
53
80
  """
54
- reactant_dative_removed: bool = any(remove_dative_bonds_in_mol(reactant) for reactant in reaction.iterateReactants())
81
+ reactant_dative_removed: bool = any(
82
+ remove_dative_bonds_in_mol(reactant) for reactant in reaction.iterateReactants())
55
83
  product_dative_removed: bool = any(remove_dative_bonds_in_mol(product) for product in reaction.iterateProducts())
56
84
  return reactant_dative_removed or product_dative_removed
57
85
 
@@ -1,6 +1,6 @@
1
1
  # Author Yechen Qiao
2
2
  # Common Molecule Utilities for Molecule Transfers with Sapio
3
-
3
+ from indigo import IndigoObject
4
4
  from rdkit import Chem
5
5
  from rdkit.Chem import Crippen, MolToInchi
6
6
  from rdkit.Chem import Descriptors
@@ -10,7 +10,7 @@ from rdkit.Chem.MolStandardize import rdMolStandardize
10
10
  from rdkit.Chem.SaltRemover import SaltRemover
11
11
  from rdkit.Chem.rdchem import Mol, RWMol, Bond
12
12
 
13
- from sapiopycommons.chem.IndigoMolecules import indigo, renderer, indigo_inchi
13
+ from sapiopycommons.chem.IndigoMolecules import indigo, renderer, indigo_inchi, get_aromatic_dearomatic_forms
14
14
 
15
15
  metal_disconnector = rdMolStandardize.MetalDisconnector()
16
16
  tautomer_params = Chem.MolStandardize.rdMolStandardize.CleanupParameters()
@@ -247,7 +247,7 @@ def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
247
247
  molecule["image"] = None
248
248
  # We need to test the INCHI can be loaded back to indigo.
249
249
  indigo_mol = indigo.loadMolecule(molBlock)
250
- indigo_mol.aromatize()
250
+ indigo_mol = get_aromatic_dearomatic_forms(indigo_mol)[0] # Get the aromatic form of the molecule.
251
251
  if enhanced_stereo:
252
252
  # Remove enhanced stereo layer when generating InChI as the stereo hash is generated separately for reg.
253
253
  Chem.CanonicalizeEnhancedStereo(inchi_mol)
@@ -6,6 +6,7 @@ from sapiopylib.rest.CustomReportService import CustomReportManager
6
6
  from sapiopylib.rest.DataMgmtService import DataMgmtServer
7
7
  from sapiopylib.rest.pojo.CustomReport import CustomReportCriteria, CustomReport, RawReportTerm, ReportColumn
8
8
  from sapiopylib.rest.pojo.datatype.FieldDefinition import FieldType
9
+ # noinspection PyProtectedMember
9
10
  from sapiopylib.rest.utils.autopaging import SapioPyAutoPager, PagerResultCriteriaType, _default_report_page_size, \
10
11
  _default_record_page_size
11
12
  from sapiopylib.rest.utils.recordmodel.PyRecordModel import PyRecordModel
@@ -61,6 +62,12 @@ class CustomReportDictAutoPager(_DictReportPagerBase):
61
62
  def __init__(self, user: UserIdentifier, report_criteria: CustomReportCriteria,
62
63
  page_number: int = 0, page_size: int = _default_report_page_size):
63
64
  """
65
+ IMPORTANT NOTICE: Custom reports that are not single data type (i.e. they have terms or columns from multiple
66
+ data types) may not be 100% time accurate. Such reports use the system's ancestor table to retrieve the
67
+ relationships, and this table takes some time to update after relationships are updated, especially for more
68
+ populous data types. If you need 100% time accurate results to the current state of the records and
69
+ relationships in the database, you should query for the records directly instead of using a custom report.
70
+
64
71
  :param user: The current webhook context or a user object to send requests from.
65
72
  :param report_criteria: The custom report criteria to run.
66
73
  :param page_number: The page number to start on. The first page is page 0.
@@ -82,6 +89,12 @@ class SystemReportDictAutoPager(_DictReportPagerBase):
82
89
  def __init__(self, user: UserIdentifier, report_name: str,
83
90
  page_number: int = 0, page_size: int = _default_report_page_size):
84
91
  """
92
+ IMPORTANT NOTICE: Custom reports that are not single data type (i.e. they have terms or columns from multiple
93
+ data types) may not be 100% time accurate. Such reports use the system's ancestor table to retrieve the
94
+ relationships, and this table takes some time to update after relationships are updated, especially for more
95
+ populous data types. If you need 100% time accurate results to the current state of the records and
96
+ relationships in the database, you should query for the records directly instead of using a custom report.
97
+
85
98
  :param user: The current webhook context or a user object to send requests from.
86
99
  :param report_name: The name of the system report to run.
87
100
  :param page_number: The page number to start on. The first page is page 0.
@@ -153,7 +166,7 @@ class _RecordReportPagerBase(SapioPyAutoPager[CustomReportCriteria, WrappedType
153
166
  if id_index == -1:
154
167
  raise SapioException(f"This report does not contain a Record ID column for the given record model type "
155
168
  f"{self._data_type}.")
156
- ids: list[int] = [row[id_index] for row in report.result_table]
169
+ ids: set[int] = {row[id_index] for row in report.result_table}
157
170
  for row in self._rec_handler.query_models_by_id(self._query_type, ids, page_size=report.page_size):
158
171
  queue.put(row)
159
172
  if report.has_next_page:
@@ -172,6 +185,12 @@ class CustomReportRecordAutoPager(_RecordReportPagerBase):
172
185
  wrapper_type: type[WrappedType] | str, page_number: int = 0,
173
186
  page_size: int = _default_record_page_size):
174
187
  """
188
+ IMPORTANT NOTICE: Custom reports that are not single data type (i.e. they have terms or columns from multiple
189
+ data types) may not be 100% time accurate. Such reports use the system's ancestor table to retrieve the
190
+ relationships, and this table takes some time to update after relationships are updated, especially for more
191
+ populous data types. If you need 100% time accurate results to the current state of the records and
192
+ relationships in the database, you should query for the records directly instead of using a custom report.
193
+
175
194
  :param user: The current webhook context or a user object to send requests from.
176
195
  :param report_criteria: The custom report criteria to run.
177
196
  :param wrapper_type: The record model wrapper type or data type name of the records being searched for.
@@ -197,6 +216,12 @@ class SystemReportRecordAutoPager(_RecordReportPagerBase):
197
216
  def __init__(self, user: UserIdentifier, report_name: str, wrapper_type: type[WrappedType] | str,
198
217
  page_number: int = 0, page_size: int = _default_record_page_size):
199
218
  """
219
+ IMPORTANT NOTICE: Custom reports that are not single data type (i.e. they have terms or columns from multiple
220
+ data types) may not be 100% time accurate. Such reports use the system's ancestor table to retrieve the
221
+ relationships, and this table takes some time to update after relationships are updated, especially for more
222
+ populous data types. If you need 100% time accurate results to the current state of the records and
223
+ relationships in the database, you should query for the records directly instead of using a custom report.
224
+
200
225
  :param user: The current webhook context or a user object to send requests from.
201
226
  :param report_name: The name of the system report to run.
202
227
  :param wrapper_type: The record model wrapper type or data type name of the records being searched for.
@@ -279,7 +279,7 @@ class TermBuilder:
279
279
 
280
280
  :param a: The first term in the operation.
281
281
  :param b: The second term in the operation.
282
- :param is_negated: Whether the returned term should be negated (i.e. turn this into an xnor operation).
282
+ :param is_negated: Whether the returned term should be negated (i.e. turn this into an XNOR operation).
283
283
  :return: A composite report term for "A xor B".
284
284
  """
285
285
  return TermBuilder.and_terms(TermBuilder.or_terms(a, b),