datamol.io
¶
open_df(path, **kwargs)
¶
Open a dataframe file whatever its filetype from
csv, excel, parquet, json, sdf
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
path to the file. |
required |
**kwargs |
Any
|
keyword arguments to pass to the underlying reader. |
{}
|
Source code in datamol/io.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
|
read_csv(urlpath, smiles_column=None, mol_column='mol', **kwargs)
¶
Read a CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urlpath |
Union[str, PathLike, IO]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
smiles_column |
Optional[str]
|
Use this column to build a mol column. |
None
|
mol_column |
str
|
Name to give to the mol column. If not None a mol column will be build. Avoid when loading a very large file. |
'mol'
|
**kwargs |
Any
|
Arguments to pass to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
a |
Source code in datamol/io.py
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 |
|
read_excel(urlpath, sheet_name=0, smiles_column=None, mol_column='mol', **kwargs)
¶
Read an excel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urlpath |
Union[str, PathLike, IO]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
sheet_name |
Optional[Union[str, int, list]]
|
see |
0
|
mol_column |
str
|
Name to give to the mol column. If not None a mol column will be build. Avoid when loading a very large file. |
'mol'
|
mol_column |
str
|
name to give to the mol column. |
'mol'
|
**kwargs |
Any
|
Arguments to pass to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
a |
Source code in datamol/io.py
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 |
|
read_mol2file(urlpath, sanitize=True, cleanup_substructures=True, remove_hs=True, fail_if_invalid=False)
¶
Read a Mol2 File
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urlpath |
Union[str, PathLike, IO]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
sanitize |
bool
|
Whether to sanitize the molecules. |
True
|
remove_hs |
bool
|
Whether to remove the existing hydrogens in the SDF files. |
True
|
cleanup_substructures |
bool
|
Whether to clean up substructure in the Mol2 Files. |
True
|
fail_if_invalid |
bool
|
If set to true, the parser will raise an exception if the molecule is invalid instead of returning None. |
False
|
Source code in datamol/io.py
275 276 277 278 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 |
|
read_molblock(molblock, sanitize=True, strict_parsing=True, remove_hs=True, fail_if_invalid=False)
¶
Read a Mol block.
Note that potential molecule properties are not read.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
molblock |
str
|
String containing the Mol block. |
required |
sanitize |
bool
|
Whether to sanitize the molecules. |
True
|
strict_parsing |
bool
|
If set to false, the parser is more lax about correctness of the contents. |
True
|
remove_hs |
bool
|
Whether to remove the existing hydrogens in the SDF files. |
True
|
fail_if_invalid |
bool
|
If set to true, the parser will raise an exception if the molecule is invalid instead of returning None. |
False
|
Source code in datamol/io.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
read_pdbblock(molblock, sanitize=True, remove_hs=True, flavor=0, proximity_bonding=True)
¶
Read a PDB string block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
molblock |
str
|
String containing the Mol block. |
required |
sanitize |
bool
|
Whether to sanitize the molecules. |
True
|
remove_hs |
bool
|
Whether to remove the existing hydrogens in the SDF files. |
True
|
flavor |
int
|
RDKit flavor options. |
0
|
proximity_bonding |
bool
|
Whether to toggles automatic proximity bonding. |
True
|
Source code in datamol/io.py
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 |
|
read_pdbfile(urlpath, sanitize=True, remove_hs=True, flavor=0, proximity_bonding=True)
¶
Read a PDB file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urlpath |
Union[str, PathLike]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
sanitize |
bool
|
Whether to sanitize the molecules. |
True
|
remove_hs |
bool
|
Whether to remove the existing hydrogens in the SDF files. |
True
|
flavor |
int
|
RDKit flavor options. |
0
|
proximity_bonding |
bool
|
Whether to toggles automatic proximity bonding. |
True
|
Returns:
Name | Type | Description |
---|---|---|
mol |
Mol
|
a molecule |
Source code in datamol/io.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
read_sdf(urlpath, sanitize=True, as_df=False, smiles_column='smiles', mol_column=None, include_private=False, include_computed=False, strict_parsing=True, remove_hs=True, max_num_mols=None, discard_invalid=True, n_jobs=1)
¶
Read an SDF file.
Note: This function is meant to be used with dataset that fit in-memory.
For a more advanced usage we suggest you to use directly Chem.ForwardSDMolSupplier
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urlpath |
Union[str, PathLike, IO]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
sanitize |
bool
|
Whether to sanitize the molecules. |
True
|
as_df |
bool
|
Whether to return a list mol or a pandas DataFrame. |
False
|
smiles_column |
Optional[str]
|
Name of the SMILES column. Only relevant if |
'smiles'
|
mol_column |
Optional[str]
|
Name of the mol column. Only relevant if |
None
|
include_private |
bool
|
Include private properties in the columns. Only relevant if
|
False
|
include_computed |
bool
|
Include computed properties in the columns. Only relevant if
|
False
|
strict_parsing |
bool
|
If set to false, the parser is more lax about correctness of the contents. |
True
|
remove_hs |
bool
|
Whether to remove the existing hydrogens in the SDF files. |
True
|
max_num_mols |
Optional[int]
|
Maximum number of molecules to read from the SDF file. Read all by default when set
to |
None
|
discard_invalid |
bool
|
Discard the molecules that failed to be read correctly. Otherwise,
invalid molecules will be loaded as |
True
|
n_jobs |
Optional[int]
|
Optional number of jobs for parallelization of |
1
|
Source code in datamol/io.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 |
|
read_smi(urlpath)
¶
Read a list of smiles from am .smi
file.
Note: We strongly recommend you to use dm.read_csv
or pandas.read_csv
instead
of dm.read_smi
since .smi
files are CSV-like format. The only difference are the
default settings which changes:
- The default separator is a space
instead of a comma
,
. - The headers of the column are not included.
By modifying the args of dm.read_csv()
, you will be able to read an .smi
files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urlpath |
Union[str, Path, IOBase, OpenFile]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
Source code in datamol/io.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
|
save_df(data, path, **kwargs)
¶
Save a dataframe file whatever its filetype from
csv, excel, parquet, json, sdf
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
dataframe to save. |
required |
path |
str
|
path to save the file. |
required |
**kwargs |
Any
|
additional arguments to pass that are specific to the file save type. |
{}
|
Source code in datamol/io.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
|
to_molblock(mol, include_stereo=True, conf_id=-1, kekulize=True, force_V3000=False)
¶
Convert a molecule to a mol block string.
Note that any molecule properties are lost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
include_stereo |
bool
|
Toggles inclusion of stereochemical information in the output. |
True
|
conf_id |
int
|
Selects which conformation to output. |
-1
|
kekulize |
bool
|
Triggers kekulization of the molecule before it's written, as suggested by the MDL spec. |
True
|
force_V3000 |
bool
|
Force generation a V3000 mol block (happens automatically with more than 999 atoms or bonds). |
False
|
Source code in datamol/io.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
to_pdbblock(mol, conf_id=-1)
¶
Convert a molecule to a PDB string block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
conf_id |
int
|
Selects which conformation to use. |
-1
|
Source code in datamol/io.py
415 416 417 418 419 420 421 422 423 |
|
to_pdbfile(mol, urlpath, conf_id=-1)
¶
Save a molecule to a PDB file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
A molecule. |
required |
urlpath |
Union[str, PathLike]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
conf_id |
int
|
Selects which conformation to use. |
-1
|
Source code in datamol/io.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
to_sdf(mols, urlpath, smiles_column='smiles', mol_column=None)
¶
Write molecules to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
Union[Mol, Sequence[Mol], DataFrame]
|
a dataframe, a molecule or a list of molecule. |
required |
urlpath |
Union[str, PathLike, IO]
|
Path to a file or a file-like object. Path can be remote or local. |
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
|
Source code in datamol/io.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
to_smi(mols, urlpath, error_if_empty=False)
¶
Save a list of molecules in an .smi
file.
Note: We strongly recommend you to use dm.to_csv
instead
of dm.to_smi
since .smi
files are CSV-like format. The only difference are the
default settings which changes:
- The default separator is a space
instead of a comma
,
. - The headers of the column are not included.
By modifying the args of dm.to_csv()
, you will be able to save a SMI compatible file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
Sequence[Mol]
|
a list of molecules. |
required |
urlpath |
Union[str, PathLike, IO]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
error_if_empty |
bool
|
whether to raise and error if the input list is empty. |
False
|
Source code in datamol/io.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
to_xlsx(mols, urlpath, smiles_column='smiles', mol_column='mol', mol_size=[300, 300])
¶
Write molecules to an Excel file with a molecule column as an RDKit rendered image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
Union[Mol, Sequence[Mol], DataFrame]
|
a dataframe, a molecule or a list of molecule. |
required |
urlpath |
Union[str, PathLike]
|
Path to a file or a file-like object. Path can be remote or local. |
required |
smiles_column |
Optional[str]
|
Column name to extract the molecule. |
'smiles'
|
mol_column |
str
|
Column name to extract the molecule. It takes
precedence over |
'mol'
|
Source code in datamol/io.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|