datamol.viz
¶
Vizualize molecule in 2D or 3D¶
Generate an image out of a molecule or a list of molecules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
Union[List[Union[Mol, str]], Mol, str]
|
One or a list of molecules. |
required |
legends |
Union[List[Union[str, None]], str, None]
|
A string or a list of string as legend for every molecules. |
None
|
n_cols |
int
|
Number of molecules per column. |
4
|
use_svg |
bool
|
Whether to ouput an SVG (or a PNG). |
True
|
mol_size |
Union[Tuple[int, int], int]
|
A int or a tuple of int defining the size per molecule. |
(300, 300)
|
highlight_atom |
Optional[List[List[int]]]
|
the atoms to highlight. |
None
|
highlight_bond |
Optional[List[List[int]]]
|
The bonds to highlight. |
None
|
outfile |
Optional[str]
|
Path where to save the image (local or remote path). |
None
|
max_mols |
int
|
The maximum number of molecules to display. |
32
|
max_mols_ipython |
int
|
The maximum number of molecules to display when running within an IPython environment. |
50
|
copy |
bool
|
Whether to copy the molecules or not. |
True
|
indices |
bool
|
Whether to draw the atom indices. |
False
|
bond_indices |
bool
|
Whether to draw the bond indices. |
False
|
bond_line_width |
int
|
The width of the bond lines. |
2
|
legend_fontsize |
int
|
Font size for the legend. |
16
|
kekulize |
bool
|
Run kekulization routine on molecules. Skipped if fails. |
True
|
align |
Union[Mol, str, bool]
|
Whether to align the 2D coordinates of the molecules.
- If set to True, align all molecules with |
False
|
**kwargs |
Any
|
Additional arguments to pass to the drawing function. See RDKit
documentation related to |
{}
|
Source code in datamol/viz/_viz.py
16 17 18 19 20 21 22 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
Visualize the conformer(s) of a molecule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mol |
Mol
|
a molecule. |
required |
conf_id |
int
|
The ID of the conformer to show. -1 shows
the first conformer. Only works if |
-1
|
n_confs |
Optional[Union[int, List[int]]]
|
Can be a number of conformers to shows or a list of conformer indices. When None, only the first conformer is displayed. When -1, show all conformers. |
None
|
align_conf |
bool
|
Whether to align conformers together. |
True
|
n_cols |
int
|
Number of columns. Defaults to 3. |
3
|
sync_views |
bool
|
Wether to sync the multiple views. |
True
|
remove_hs |
bool
|
Wether to remove the hydrogens of the conformers. |
True
|
width |
str
|
The width of the returned view. Defaults to "auto". |
'auto'
|
Source code in datamol/viz/_conformers.py
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
Specific plotting functions¶
Source code in datamol/viz/_circle_grid.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 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 232 233 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 273 274 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 321 322 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 354 355 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 |
|
__call__(outfile=None)
¶
Draw the circular molecule and save to file if outfile is provided
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outfile |
Optional[str]
|
output file name |
None
|
Source code in datamol/viz/_circle_grid.py
278 279 280 281 282 283 284 285 286 287 |
|
__init__(center_mol, ring_mols, legend=None, margin=50, ring_scaler=1.0, act_mapper=None, align=None, use_svg=True, line_width=None, ring_color=None, ring_mol_start_angles_degrees=None, center_mol_highlight_atoms=None, center_mol_highlight_bonds=None, ring_mol_highlight_atoms=None, ring_mol_highlight_bonds=None, kekulize=True, layout_random_seed=19, **kwargs)
¶
Show molecules in concentric rings, with one molecule at the center
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center_mol |
Union[Mol, str]
|
Molecule at center of the rings |
required |
ring_mols |
List[List[Union[Mol, str]]]
|
List of molecule for each level of concentric rings around the center mol |
required |
legend |
Optional[str]
|
optional global legend for the figure |
None
|
margin |
int
|
Margin between the circle layers |
50
|
ring_scaler |
float
|
Scale the size of the molecules in each circle by this factor compared to the center molecule |
1.0
|
act_mapper |
Optional[dict]
|
dictionary of activity for each molecule |
None
|
align |
Optional[Union[Mol, str, bool]]
|
Whether to align the 2D coordinates of the molecules.
- If set to True, align all molecules with |
None
|
use_svg |
bool
|
Whether to use SVG or use PNG |
True
|
line_width |
Optional[float]
|
Width of the lines to draw |
None
|
center_mol_highlight_atoms |
Optional[List[int]]
|
List of atom indices to highlight for the center molecule |
None
|
center_mol_highlight_bonds |
Optional[List[int]]
|
List of bond indices to highlight for the center molecule |
None
|
ring_mol_highlight_atoms |
Optional[List[List[int]]]
|
List of list of atom indices to highlight for molecules at each level of the concentric rings |
None
|
ring_mol_highlight_bonds |
Optional[List[List[int]]]
|
List of list of bond indices to highlight for molecules at each level of the concentric rings |
None
|
ring_color |
Optional[DatamolColor]
|
Color of the concentric rings. Set to None to not draw any ring. |
None
|
ring_mol_start_angles_degrees |
Optional[List[float]]
|
List of angles in degrees to start drawing the molecules at each level of the concentric rings. If None then a random position will be used. |
None
|
kekulize |
bool
|
Whether to kekulize the molecules before drawing. |
True
|
layout_random_seed |
Optional[int]
|
Random seed for the layout of the molecules. Set to None for no seed. |
19
|
**kwargs |
Any
|
Additional arguments to pass to the drawing function. See RDKit
documentation related to |
{}
|
Source code in datamol/viz/_circle_grid.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 |
|
draw()
¶
Create and draw the circular molecule image
Source code in datamol/viz/_circle_grid.py
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 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
Show molecules in concentric rings, with one molecule at the center
Args:
center_mol: Molecule at center of the rings
ring_mols: List of molecule for each level of concentric rings around the center mol
legend: optional global legend for the figure
margin: Margin between the circle layers
ring_scaler: Scale the size of the molecules in each circle by this factor compared to the center molecule
act_mapper: dictionary of activity for each molecule
align: Whether to align the 2D coordinates of the molecules.
- If set to True, align all molecules with dm.align.auto_align_many()
.
- If set to a molecule, it is used as a template for alignment with dm.align.template_align()
.
- If set to False, no alignment is performed.
- If set to None (default), the ring (peripheral) molecules are aligned to the center molecules.
use_svg: Whether to use SVG or use PNG
center_mol_highlight_atoms: List of atom indices to highlight for the center molecule
center_mol_highlight_bonds: List of bond indices to highlight for the center molecule
ring_mol_highlight_atoms: List of list of atom indices to highlight for molecules at each level of the concentric rings
ring_mol_highlight_bonds: List of list of bond indices to highlight for molecules at each level of the concentric rings
ring_color: Color of the concentric rings. Set to None to not draw any ring.
ring_mol_start_angles_degrees: List of angles in degrees to start drawing the molecules at each level of the concentric
rings. If None then a random position will be used.
kekulize: Whether to kekulize the molecules before drawing.
layout_random_seed: Random seed for the layout of the molecules. Set to None for no seed.
outfile: Optional path to the save the output file.
**kwargs: Additional arguments to pass to the drawing function. See RDKit
documentation related to MolDrawOptions
for more details at
https://www.rdkit.org/docs/source/rdkit.Chem.Draw.rdMolDraw2D.html.
Source code in datamol/viz/_circle_grid.py
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 93 |
|
Vizualize 2D molecule with highlighted substructures¶
Create an image of a list of molecules with substructure matches using lasso-based highlighting. Substructure matching is optional and it's also possible to pass a list of list of atom indices to highlight.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_molecules |
Union[str, Mol, List[Union[str, Mol]]]
|
One or a list of molecules to be highlighted. |
required |
search_molecules |
Union[str, List[str], Mol, List[Mol]]
|
The substructure to be highlighted. |
None
|
atom_indices |
Optional[Union[List[int], List[List[int]]]]
|
Atom indices to be highlighted as substructure using the lasso visualization. |
None
|
legends |
Union[List[Union[str, None]], str, None]
|
A string or a list of string as legend for every molecules. |
None
|
n_cols |
int
|
Number of molecules per column. |
4
|
mol_size |
Tuple[int, int]
|
The size of the image to be returned |
(300, 300)
|
use_svg |
Optional[bool]
|
Whether to return an svg or png image |
True
|
draw_mols_same_scale |
bool
|
Whether to draw all the molecules on the same scale. This has the same effect as the |
True
|
r_min |
float
|
Radius of the smallest circle around atoms. Length is relative to average bond length (1 = avg. bond len). |
0.3
|
r_dist |
float
|
Incremental increase of radius for the next substructure. |
0.13
|
relative_bond_width |
float
|
Distance of line to "bond" (line segment between the two atoms). Size is relative to |
0.5
|
color_list |
Optional[List[DatamolColor]]
|
List of tuples with RGBA or RGB values specifying the color of the highlighting. |
None
|
line_width |
int
|
width of drawn lines. |
2
|
scale_padding |
float
|
Padding around the molecule when drawing to scale. |
1.0
|
verbose |
bool
|
Whether to print the verbose information. |
False
|
highlight_atoms |
Optional[List[List[int]]]
|
The atoms to highlight, a list for each molecule. It's the |
None
|
highlight_bonds |
Optional[List[List[int]]]
|
The bonds to highlight, a list for each molecule. It's the |
None
|
highlight_atom_colors |
Optional[List[Dict[int, DatamolColor]]]
|
The colors to use for highlighting atoms, a list of dict mapping atom index to color for each molecule. |
None
|
highlight_bond_colors |
Optional[List[Dict[int, DatamolColor]]]
|
The colors to use for highlighting bonds, a list of dict mapping bond index to color for each molecule. |
None
|
**kwargs |
Any
|
Additional arguments to pass to the drawing function. See RDKit
documentation related to |
{}
|
Source code in datamol/viz/_lasso_highlight.py
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 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 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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 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 558 559 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
|