datamol.convert
¶
from_df(df, smiles_column='smiles', mol_column=None, conserve_smiles=False, sanitize=True)
¶
Convert a dataframe to a list of mols.
For the reverse operation, you might to check dm.to_df()
.
Note
If smiles_column
is used to build the molecules, this property
is removed from the molecules' properties. You can decide to conserve
the SMILES column by setting conserve_smiles
to True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
pd.DataFrame
|
a dataframe. |
required |
smiles_column |
Optional[str]
|
Column name to extract the molecule. |
'smiles'
|
mol_column |
Optional[str]
|
Column name to extract the molecule. It takes
precedence over |
None
|
conserve_smiles |
bool
|
Whether to conserve the SMILES in the mols' props. |
False
|
sanitize |
bool
|
Whether to sanitize if |
True
|
Source code in datamol/convert.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
from_inchi(inchi, sanitize=True, remove_hs=True)
¶
Convert an InChi to a mol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inchi |
Optional[str]
|
an inchi string. |
required |
sanitize |
bool
|
do sanitize. |
True
|
remove_hs |
bool
|
do remove hs. |
True
|
Returns:
Type | Description |
---|---|
Optional[Mol]
|
mol |
Source code in datamol/convert.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
from_selfies(selfies, as_mol=False)
¶
Convert a SEFLIES to a smiles or a mol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selfies |
str
|
a selfies. |
required |
as_mol |
str
|
whether to return a mol or a smiles. |
False
|
Returns:
Type | Description |
---|---|
Optional[Union[str, Mol]]
|
smiles or mol. |
Source code in datamol/convert.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
from_smarts(smarts)
¶
Convert a SMARTS string to a molecule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smarts |
Optional[str]
|
a smarts string |
required |
Source code in datamol/convert.py
352 353 354 355 356 357 358 359 360 361 |
|
render_mol_df(df)
¶
Render the molecules column in a dataframe. The rendering is performed in-place only. So nothing is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
pd.DataFrame
|
a dataframe. |
required |
Source code in datamol/convert.py
496 497 498 499 500 501 502 503 504 505 |
|
smiles_as_smarts(mol, keep_hs=True)
¶
Convert a smiles to a smarts if possible
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
a molecule. |
required |
keep_hs |
bool
|
Whether to keep hydrogen. This will increase the count of H atoms for atoms with attached hydrogens to create a valid smarts without further substitution allowed e.g. [H]-[CH]-[] -> [H]-[CH2]-[] |
True
|
Returns:
Type | Description |
---|---|
Optional[str]
|
smarts of the molecule |
Source code in datamol/convert.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
to_df(mols, smiles_column='smiles', mol_column=None, include_private=False, include_computed=False, render_df_mol=True, render_all_df_mol=False)
¶
Convert a list of mols to a dataframe using each mol properties as a column.
For the reverse operation, you might to check dm.from_df()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
List[Mol]
|
a molecule. |
required |
smiles_column |
Optional[str]
|
name of the SMILES column. |
'smiles'
|
mol_column |
Optional[str]
|
Name of the column. If not None, rdkit.Chem.PandaTools is used to add a molecule column. |
None
|
include_private |
bool
|
Include private properties in the columns. |
False
|
include_computed |
bool
|
Include computed properties in the columns. |
False
|
render_df_mol |
bool
|
whether to render the molecule in the dataframe to images. If called once, it will be applied for the newly created dataframe with mol in it. |
True
|
render_all_df_mol |
bool
|
Whether to render all pandas dataframe mol column as images. |
False
|
Source code in datamol/convert.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
to_inchi(mol)
¶
Convert a mol to a standard Inchi.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
a molecule. |
required |
Source code in datamol/convert.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
to_inchi_non_standard(mol, fixed_hydrogen_layer=True, undefined_stereocenter=True, reconnected_metal_layer=True, tautomerism_keto_enol=True, tautomerism_15=True, options=None)
¶
Convert a mol to a non-standard Inchi.
Note that turning all the flags to False
will result in the standard Inchi.
Warning: this function will return a non-standard Inchi. See https://www.inchi-trust.org/technical-faq-2 for details.
It's important to not mix standard and non-standard InChi. If you don't know
much about non-standard InChi, we highly recommend you to use the
standard InChi with dm.to_inchi()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
a molecule. |
required |
fixed_hydrogen_layer |
bool
|
whether to include a fixed hydrogen layer ( |
True
|
undefined_stereocenter |
bool
|
whether to include an undefined stereocenter layer ( |
True
|
reconnected_metal_layer |
bool
|
whether to include reconnected metals ( |
True
|
tautomerism_keto_enol |
bool
|
whether to account tautomerism keto-enol ( |
True
|
tautomerism_15 |
bool
|
whether to account 1,5-tautomerism ( |
True
|
options |
Optional[List[str]]
|
More InchI options in a form of a list of string. Example:
|
None
|
Source code in datamol/convert.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
to_inchikey(mol)
¶
Convert a mol to a standard InchiKey.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
a molecule |
required |
Source code in datamol/convert.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
to_inchikey_non_standard(mol, fixed_hydrogen_layer=True, undefined_stereocenter=True, reconnected_metal_layer=True, tautomerism_keto_enol=True, tautomerism_15=True, options=None)
¶
Convert a mol to a non-standard InchiKey.
Note that turning all the flags to False
will result in the standard InchiKey.
Warning: this function will return a non-standard InchiKey. See https://www.inchi-trust.org/technical-faq-2 for details.
It's important to not mix standard and non-standard InChiKey. If you don't know
much about non-standard InchiKey, we highly recommend you to use the
standard InchiKey with dm.to_inchikey()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
a molecule |
required |
fixed_hydrogen_layer |
bool
|
whether to include a fixed hydrogen layer ( |
True
|
undefined_stereocenter |
bool
|
whether to include an undefined stereocenter layer ( |
True
|
reconnected_metal_layer |
bool
|
whether to include reconnected metals ( |
True
|
tautomerism_keto_enol |
bool
|
whether to account tautomerism keto-enol ( |
True
|
tautomerism_15 |
bool
|
whether to account 1,5-tautomerism ( |
True
|
options |
Optional[List[str]]
|
More InchI options in a form of a list of string. Example:
|
None
|
Source code in datamol/convert.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
to_selfies(mol)
¶
Convert a mol to SELFIES.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Union[str, Mol]
|
a molecule or a SMILES. |
required |
Returns:
Name | Type | Description |
---|---|---|
selfies |
Optional[str]
|
SELFIES string. |
Source code in datamol/convert.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
to_smarts(mol)
¶
Convert a mol to SMARTS format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
Source code in datamol/convert.py
248 249 250 251 252 253 254 255 256 257 258 |
|
to_smiles(mol, canonical=True, isomeric=True, kekulize=False, ordered=False, explicit_bonds=False, explicit_hs=False, randomize=False, cxsmiles=False, allow_to_fail=False, with_atom_indices=False)
¶
Convert a mol to a SMILES.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
canonical |
bool
|
if false no attempt will be made to canonicalize the molecule. |
True
|
isomeric |
bool
|
whether to include information about stereochemistry in the SMILES. |
True
|
kekulize |
bool
|
whether to return the kekule version of the SMILES. |
False
|
ordered |
bool
|
whether to force reordering of the atoms first. |
False
|
explicit_bonds |
bool
|
if true, all bond orders will be explicitly indicated in the output SMILES. |
False
|
explicit_hs |
bool
|
if true, all H counts will be explicitly indicated in the output SMILES. |
False
|
randomize |
bool
|
whether to randomize the generated smiles. Override |
False
|
cxsmiles |
bool
|
Whether to return a CXSMILES instead of a SMILES. |
False
|
allow_to_fail |
bool
|
Raise an error if the conversion to SMILES fails. Return None otherwise. |
False
|
with_atom_indices |
bool
|
Whether to add atom indices to the SMILES. |
False
|
Source code in datamol/convert.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|