rdworks 0.35.1__py3-none-any.whl → 0.36.2__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.
rdworks/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = '0.35.1'
1
+ __version__ = '0.36.2'
2
2
 
3
3
  from rdworks.conf import Conf
4
4
  from rdworks.mol import Mol
rdworks/conf.py CHANGED
@@ -11,7 +11,7 @@ from mendeleev import element
11
11
  from ase.optimize import FIRE
12
12
 
13
13
  from rdkit import Chem
14
- from rdkit.Chem import rdMolTransforms, AllChem, rdMolAlign
14
+ from rdkit.Chem import rdMolTransforms, AllChem, rdMolAlign, rdmolops
15
15
  from rdkit.Chem.Draw import rdMolDraw2D
16
16
  from PIL import Image
17
17
 
@@ -39,6 +39,8 @@ class Conf:
39
39
  self.rdmol = None # must contain one and only one rdkit conformer
40
40
  self.name = name
41
41
  self.natoms = 0
42
+ self.charge = 0 # molecular charge
43
+ self.spin = 1 # molecular spin multiplicity for ASE
42
44
  self.props = {}
43
45
 
44
46
  if molecule is None:
@@ -60,6 +62,7 @@ class Conf:
60
62
  tot_atoms = self.rdmol.GetNumAtoms(onlyExplicit=False)
61
63
  assert num_atoms == tot_atoms, "Conf() Error: missing hydrogens"
62
64
  self.natoms = num_atoms
65
+ self.charge = rdmolops.GetFormalCharge(self.rdmol)
63
66
  self.props.update({'atoms': num_atoms})
64
67
 
65
68
  assert self.rdmol.GetConformer().Is3D(), "Conf() Error: not 3D"
@@ -214,6 +217,8 @@ class Conf:
214
217
  # assuming ASE calculator
215
218
  with io.StringIO() as logfile:
216
219
  ase_atoms = ase.Atoms(symbols=self.symbols(), positions=self.positions())
220
+ ase_atoms.info['charge'] = self.charge
221
+ ase_atoms.info['spin'] = self.spin
217
222
  ase_atoms.calc = calculator
218
223
  FIRE(ase_atoms, logfile=logfile).run(fmax=fmax)
219
224
  lines = [l.strip().split()[1:] for l in logfile.getvalue().split('\n') if l.startswith('FIRE')]
@@ -366,9 +371,14 @@ class Conf:
366
371
  else:
367
372
  try:
368
373
  ase_atoms = ase.Atoms(symbols=self.symbols(), positions=self.positions())
374
+ ase_atoms.info['charge'] = self.charge
375
+ ase_atoms.info['spin'] = self.spin
369
376
  ase_atoms.calc = calculator
370
377
  PE = ase_atoms.get_potential_energy() # np.array
371
- PE = ev2kcalpermol * float(PE[0]) # np.float64 to float
378
+ if isinstance(PE, float):
379
+ PE = ev2kcalpermol * PE
380
+ elif isinstance(PE, np.ndarray | list):
381
+ PE = ev2kcalpermol * float(PE[0]) # np.float64 to float
372
382
  self.props.update({'E_tot(kcal/mol)': PE})
373
383
 
374
384
  return PE
rdworks/mol.py CHANGED
@@ -3,6 +3,7 @@ import itertools
3
3
  import json
4
4
  import logging
5
5
  import tempfile
6
+ import os
6
7
 
7
8
  from io import StringIO, BytesIO
8
9
  from pathlib import Path
@@ -367,7 +368,7 @@ class Mol:
367
368
  self.confs.append(conf)
368
369
 
369
370
  elif method.upper() == 'CONFORGE':
370
- with tempfile.NamedTemporaryFile() as tmpfile:
371
+ with tempfile.NamedTemporaryFile(suffix='.sdf', delete=False) as tmpfile:
371
372
  mol = CDPL.Chem.parseSMILES(self.smiles)
372
373
  # create and initialize an instance of the class ConfGen.ConformerGenerator which
373
374
  # will perform the actual conformer ensemble generation work
@@ -390,7 +391,7 @@ class Mol:
390
391
  CDPL.ConfGen.ReturnCode.TORSION_DRIVING_FAILED : 'torsion driving failed',
391
392
  CDPL.ConfGen.ReturnCode.CONF_GEN_FAILED : 'conformer generation failed',
392
393
  }
393
- writer = CDPL.Chem.MolecularGraphWriter( f"{tmpfile.name}.sdf", "sdf" )
394
+ writer = CDPL.Chem.MolecularGraphWriter(tmpfile.name, "sdf" )
394
395
  # SB - io.StringIO does not work with Chem.MolecularGraphWriter()
395
396
  # We have to create a temporary file and re-read it for storing individual conformers.
396
397
  try:
@@ -403,15 +404,20 @@ class Mol:
403
404
  if status == CDPL.ConfGen.ReturnCode.SUCCESS or status == CDPL.ConfGen.ReturnCode.TOO_MUCH_SYMMETRY:
404
405
  # TOO_MUCH_SYMMETRY: output ensemble may contain duplicates
405
406
  conf_gen.setConformers(mol)
406
- writer.write(mol)
407
- with Chem.SDMolSupplier(f"{tmpfile.name}.sdf", sanitize=True, removeHs=False) as sdf:
408
- self.confs = [ Conf(m) for m in sdf if m is not None ]
407
+ writer.write(mol)
409
408
  else:
410
409
  raise RuntimeError('Error: conformer generation failed: %s' % status_to_str[status])
411
410
  except Exception as e:
412
411
  raise RuntimeError('Error: conformer generation failed: %s' % str(e))
413
- # tmpfile is automatically closed and deleted here
414
-
412
+
413
+ # tmpfile is automatically closed here
414
+
415
+ with Chem.SDMolSupplier(tmpfile.name, sanitize=True, removeHs=False) as sdf:
416
+ self.confs = [ Conf(m) for m in sdf if m is not None ]
417
+
418
+ # tmpfile is not deleted here because delete=False
419
+ # we should remove the file when it is no longer needed
420
+ os.remove(tmpfile.name)
415
421
 
416
422
  # energy evaluations for ranking
417
423
  for conf in self.confs:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rdworks
3
- Version: 0.35.1
3
+ Version: 0.36.2
4
4
  Summary: Frequently used tasks built on RDKit and other tools
5
5
  Author-email: Sung-Hun Bae <sunghun.bae@gmail.com>
6
6
  Maintainer-email: Sung-Hun Bae <sunghun.bae@gmail.com>
@@ -1,10 +1,10 @@
1
- rdworks/__init__.py,sha256=UPZKHw1RajTvab15-wzdsP4UjD27yQT0n6Q5waUaJQE,1368
2
- rdworks/conf.py,sha256=BPp_uZAXXOU53tKzjZz8SsUdAvi7aK1s_zCeHfiRATk,21744
1
+ rdworks/__init__.py,sha256=IQYmK2AVX7BA--tFniboPkU1P1f3KlwhLFIUmnYtaUQ,1368
2
+ rdworks/conf.py,sha256=hi8qqcEhDMfiGAj10I7Pl65svVNeV-ihjM7lRKX7OaM,22284
3
3
  rdworks/descriptor.py,sha256=34T_dQ6g8v3u-ym8TLKbQtxIIV5TEo-d3pdedq3o-cg,2106
4
4
  rdworks/display.py,sha256=JR0gR26UpH-JCxVOaqXZCUj2MiGZSrx9Me87FncspVI,13469
5
5
  rdworks/ionized.py,sha256=5oIjMRpkX792RIpEEE2Ir96icfFaN_h21mSihhfQPAw,6713
6
6
  rdworks/matchedseries.py,sha256=A3ON4CUpQV159mu9VqgNiJ8uoQ9ePOry9d3ra4NCAgc,10377
7
- rdworks/mol.py,sha256=5ZaBIpCnKIqxbIZM0IAJ2uG5fEIlZotw1Lb2QT_IXe0,71145
7
+ rdworks/mol.py,sha256=lF5b_AIueYCfHWgrrnxbcZOFtSPe6dO4oOcovJ3GWhA,71338
8
8
  rdworks/mollibr.py,sha256=X4UBO6Ga-QmNS7RwUiaDYAx0Q5hnWs71yTkEpH02Qb4,37696
9
9
  rdworks/pka.py,sha256=NVJVfpcNEMlX5QRyLBgUM7GIT7VMjO-llAR4LWc8J2c,1656
10
10
  rdworks/readin.py,sha256=0bnVcZcAmSLqc6zu1mYcv0LdBv2agQfOpKGwpSRL9VE,11742
@@ -65,8 +65,8 @@ rdworks/predefined/misc/reactive-part-3.xml,sha256=LgWHSEbRTVmgBoIO45xbTo1xQJs0X
65
65
  rdworks/predefined/misc/reactive.xml,sha256=syedoQ6VYUfRLnxy99ObuDniJ_a_WhrWAJbTKFfJ6VY,11248
66
66
  rdworks/xtb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
67
67
  rdworks/xtb/wrapper.py,sha256=I0nW89vlJZ5Za5pCjIpjsEOFbTm7HpeNGiPgssheWn8,11350
68
- rdworks-0.35.1.dist-info/licenses/LICENSE,sha256=UOkJSBqYyQUvtCp7a-vdCANeEcLE2dnTie_eB1By5SY,1074
69
- rdworks-0.35.1.dist-info/METADATA,sha256=cmN6_DkuVc8s0zE1LClwGTv2RGbwP6lrVxPOt2hST5k,1183
70
- rdworks-0.35.1.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
71
- rdworks-0.35.1.dist-info/top_level.txt,sha256=05C98HbvBK2axUBogC_hAT_CdpOeQYGnQ6vRAgawr8s,8
72
- rdworks-0.35.1.dist-info/RECORD,,
68
+ rdworks-0.36.2.dist-info/licenses/LICENSE,sha256=UOkJSBqYyQUvtCp7a-vdCANeEcLE2dnTie_eB1By5SY,1074
69
+ rdworks-0.36.2.dist-info/METADATA,sha256=GRcE_cV1nVX4j60RB1Cm_Y69Ad_y3HrZgOwnNau177Y,1183
70
+ rdworks-0.36.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
+ rdworks-0.36.2.dist-info/top_level.txt,sha256=05C98HbvBK2axUBogC_hAT_CdpOeQYGnQ6vRAgawr8s,8
72
+ rdworks-0.36.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5