Nucleic
Nucleic class¶
The mdna.nucleic
module is the core of the MDNA toolkit, encompassing a variety of classes and functions essential for DNA structure generation, manipulation, and analysis. Below, each key component of the module is outlined with explanations of its purpose and usage. The Nucleic
class serves as the primary interface for interacting with DNA structures in the MDNA toolkit. It encapsulates both the structural properties of DNA and the trajectory information needed for molecular dynamics simulations. Key methods include:
mdna.nucleic.Nucleic
¶
Contains mdna DNA structure with reference frames and trajectory
Source code in mdna/nucleic.py
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 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 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 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 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 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
|
__init__(sequence=None, n_bp=None, traj=None, frames=None, chainids=[0, 1], circular=None)
¶
Initializes the DNA structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
str
|
The DNA sequence, e.g. 'CGCGAATTCGCG'. |
None
|
n_bp |
int
|
The number of base pairs. Default is None. |
None
|
traj |
object
|
The MDTraj trajectory. Default is None. |
None
|
frames |
ndarray
|
The reference frames of the DNA structure. Default is None. |
None
|
chainids |
list
|
The chain IDs. Default is [0,1]. |
[0, 1]
|
circular |
bool
|
A flag that indicates if the structure is circular/closed. Default is None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If both traj and frames are provided. |
ValueError
|
If frames have an invalid shape. |
ValueError
|
If the number of base pairs in the sequence and frames do not match. |
ValueError
|
If neither traj nor frames are provided. |
Notes
- If traj is provided, sequence and n_bp will be extracted from the trajectory.
- If frames is provided, n_bp will be determined from the shape of frames.
- If sequence is provided, it will be checked against the number of base pairs.
Attributes:
Name | Type | Description |
---|---|---|
sequence |
str
|
The DNA sequence. |
n_bp |
int
|
The number of base pairs. |
traj |
object
|
The MDTraj trajectory. |
frames |
ndarray
|
The reference frames of the DNA structure. |
chainids |
list
|
The chain IDs. |
circular |
bool
|
A flag that indicates if the structure is circular/closed. |
rigid |
None
|
A container for rigid base parameters class output. |
minimizer |
None
|
A container for minimizer class output. |
Source code in mdna/nucleic.py
describe()
¶
Print the DNA structure information
Source code in mdna/nucleic.py
draw(ax=None, fig=None, save=False, frame=-1, markersize=2, lw=1, helical_axis=True, backbone=True, lead=False, anti=False, triads=False, length=0.23, color_lead='k', color_anti='darkgrey', color_axis='k')
¶
Draws a 3D representation of the DNA structure with optional helical axis, backbone, lead, anti, and triads.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
object
|
Matplotlib axis. Default is None. |
None
|
fig |
object
|
Figure axis. Default is None. |
None
|
save |
bool
|
Save image as png. Default is False. |
False
|
frame |
int
|
Index of trajectory to visualize. Default is -1. |
-1
|
markersize |
int
|
Width of backbone plot. Default is 2. |
2
|
lw |
int
|
Line width of plots. Default is 1. |
1
|
helical_axis |
bool
|
Plot central axis passing through frame origins. Default is True. |
True
|
backbone |
bool
|
Plot backbone as 'o-' line plot through phosphor atoms. Default is True. |
True
|
lead |
bool
|
Plot leading strand. Default is False. |
False
|
anti |
bool
|
Plot anti-sense opposing leading strand. Default is False. |
False
|
triads |
bool
|
Plot triads in order of b_L (blue), b_N (green), b_T (red). Default is False. |
False
|
length |
float
|
Length of triad vectors. Default is 0.23. |
0.23
|
color_lead |
str
|
Color of the leading strand. Default is 'k'. |
'k'
|
color_anti |
str
|
Color of the anti strand. Default is 'darkgrey'. |
'darkgrey'
|
color_axis |
str
|
Color of the helical axis. Default is 'k'. |
'k'
|
Notes
- The function draws a 3D representation of the DNA structure using matplotlib.
- The function requires either the trajectory or reference frames to be loaded before calling.
Example
Make a DNA structure and draw the 3D representation
Source code in mdna/nucleic.py
extend(n_bp=None, sequence=None, fixed_endpoints=False, forward=True, frame=-1, shape=None, margin=1, minimize=True, plot=False, exvol_rad=2.0, temperature=300)
¶
Extend the DNA structure in the specified direction. The method updates the attributes of the DNA object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_bp |
int
|
Number of base pairs to extend the DNA structure. Defaults to None. |
None
|
sequence |
str or List
|
DNA sequence to extend the DNA structure. If not provided, the sequence will be generated randomly. Defaults to None. |
None
|
fixed_endpoints |
bool
|
Whether to fix the endpoints of the DNA structure during extension. Defaults to False. |
False
|
forward |
bool
|
Whether to extend the DNA structure in the forward direction. If False, the DNA structure will be extended in the backward direction. Defaults to True. |
True
|
frame |
int
|
The time frame to extend. Defaults to -1. |
-1
|
shape |
ndarray
|
Control points of the shape to be used for extension. The shape should be a numpy array of shape (n, 3), where n is greater than 3. Defaults to None. |
None
|
margin |
int
|
Number of base pairs to fix at the end/start of the DNA structure during extension. Defaults to 1. |
1
|
minimize |
bool
|
Whether to minimize the new DNA structure after extension. Defaults to True. |
True
|
plot |
bool
|
Whether to plot the Energy during minmization. Defaults to False. |
False
|
exvol_rad |
float
|
Excluded volume radius. Defaults to 2.0. |
2.0
|
temperature |
int
|
Temperature for equilibration. Defaults |
300
|
Raises:
Type | Description |
---|---|
ValueError
|
If the DNA structure is circular and cannot be extended. |
ValueError
|
If neither a fixed endpoint nor a length is specified for extension. |
ValueError
|
If the input sequence is invalid or the number of base pairs is invalid. |
Notes
- If the DNA structure is circular, it cannot be extended.
Example
Extend DNA structure
Source code in mdna/nucleic.py
flip(fliplist=[], deg=180, frame=-1)
¶
Flips the nucleobases of the DNA structure.
The method updates the traj
attribute of the DNA object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fliplist |
list
|
A list of base pairs to flip. Defaults to an empty list. |
[]
|
deg |
int
|
The degrees to flip. Defaults to 180. |
180
|
frame |
int
|
The frame to flip. Defaults to -1. |
-1
|
Raises:
Type | Description |
---|---|
ValueError
|
If no fliplist is provided. |
Notes
- Rotating the nucleobase by 180 degrees corresponds to the Hoogsteen base pair configuration.
Source code in mdna/nucleic.py
get_MC_traj()
¶
Get the MC sampling energy minimization trajectory of the new spline.
get_base_frames()
¶
Get the base reference frames of the DNA structure
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the base reference frames of the DNA structure. The keys are residue topologies of the MDTraj object (traj.top.residues) and the values are the reference frames in shape (n_frames, 4, 3), where the rows represent the origin, b_D, b_L, and b_N vectors. |
Source code in mdna/nucleic.py
get_frames()
¶
Get the reference frames of the DNA structure belonging to the base steps: Returns: array of reference frames of shape (n_frames, n_bp, 4, 3) where n_frames is the number of frames, n_bp is the number of base pairs, and 4 corresponds to the origin and the 3 vectors of the reference frame
Returns:
Name | Type | Description |
---|---|---|
frames |
ndarray
|
reference frames of the DNA structure |
Source code in mdna/nucleic.py
get_linking_number(frame=-1)
¶
Get the linking number of the DNA structure based on Gauss's linking number theorem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Time frame of trajectory, by default -1 |
-1
|
Returns:
Name | Type | Description |
---|---|---|
linking_number |
ndarray
|
Numpy array containing the linking number, writhe, and twist corresponding to the time frame |
Source code in mdna/nucleic.py
get_parameter(parameter_name)
¶
Get a specific parameter from the rigid base parameters class object of the DNA structure
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameter_name |
str
|
The name of the parameter to retrieve. |
required |
Notes
The following parameters can be retrieved: - shift, slide, rise, tilt, roll, twist, shear, stretch, stagger, buckle, propeller, opening
Returns:
Type | Description |
---|---|
np.ndarray: The parameter values of the DNA structure. |
Source code in mdna/nucleic.py
get_parameters(step=False, base=False)
¶
By default retuns all the parameters of the DNA structure. Use arguments to get a specific parameter group of the DNA structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
bool
|
Returns only the step parameters of consequative bases. Defaults to False. |
False
|
base |
bool
|
Returns onlt the base pair parameters of opposing bases. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
(parameters, names) (tuple) : Returns the names of the computed parameters of shape (n_frames, n_base_pairs, n_parameters) |
Source code in mdna/nucleic.py
get_rigid_object()
¶
Get the rigid base class object of the DNA structure
Returns:
Name | Type | Description |
---|---|---|
NucleicFrames |
object
|
Object representing the rigid base parameters of the DNA structure. |
Source code in mdna/nucleic.py
get_traj()
¶
Get the trajectory of the current state of the DNA structure Returns: MDtraj object
Source code in mdna/nucleic.py
invert()
¶
Inverse the direction of the DNA structure so from 5' to 3' to 3' to 5 The method updates attributes of the DNA object.
methylate(methylations=[], CpG=False, leading_strand=0, frame=-1)
¶
Methylate the nucleobases of the DNA structure.
The method updates the traj
attribute of the DNA object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
methylations |
list
|
List of base pairs to methylate. Defaults to []. |
[]
|
CpG |
bool
|
Whether to methylate CpG sites. Defaults to False. |
False
|
leading_strand |
int
|
The leading strand to methylate. Defaults to 0. |
0
|
frame |
int
|
The frame to methylate. Defaults to -1. |
-1
|
Raises:
Type | Description |
---|---|
ValueError
|
If the DNA structure is not loaded. |
ValueError
|
If the methylations list is empty. |
Notes
Using the CpG
flag will methylate the CpG sites in the DNA structure. This flag supercedes the methylations list.
Source code in mdna/nucleic.py
minimize(frame=-1, exvol_rad=2.0, temperature=300, simple=False, equilibrate_writhe=False, endpoints_fixed=False, fixed=[], dump_every=5, plot=False)
¶
Minimize the DNA structure. This method updates the of the DNA structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
The trajectory frame to minimize. Defaults to -1. |
-1
|
simple |
bool
|
Whether to use simple equilibration. Defaults to False. |
False
|
equilibrate_writhe |
bool
|
Whether to equilibrate writhe. Defaults to False. Only works for simple equilibration. |
False
|
endpoints_fixed |
bool
|
Whether the endpoints are fixed. Defaults to False. |
False
|
fixed |
list
|
List of fixed base pairs. Defaults to an empty list. |
[]
|
exvol_rad |
float
|
Excluded volume radius. Defaults to 2.0. |
2.0
|
temperature |
int
|
Temperature for equilibration. Defaults to 300. |
300
|
dump_every |
int
|
Frequency of dumping frames. Defaults to 5. |
5
|
plot |
bool
|
Whether to plot the energy. Defaults to False. |
False
|
Additional keyword arguments can be provided and will be passed to the minimizer.
Notes:
For the simple equilibation, we rely on checking whether the considered quantity starts to fluctuate around a fixed value.
This options is compatible with With the argument equilibrate_writhe, which you can specify that writhe should also be considered for equilibration.
The other option is to use the full equilibration, which is based on the actual energy of the system.
We assume the energy to converge exponentially to the equilibrated value.
This works fairly well for most examples I checked but is not entirely robust.
Considering autocorrelation has some issues when there are relaxations at different timescales.
Also, I wasn't able to use something consistent to equilibrate writhe, since that involves a barrier crossing.
It is really non-trivial to set a criterion for whether or not a globally stable value is reached.
Example
Load a DNA structure and minimize it
Source code in mdna/nucleic.py
mutate(mutations=None, complementary=True, frame=-1, verbose=False)
¶
Mutate the DNA trajectory, updating the topology and coordinates of the DNA structure.
The method updates the traj
attribute and the sequence
attribute of the DNA object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mutations |
dict
|
A dictionary containing the mutation information. The keys represent the indices of the base pairs to be mutated, and the values represent the new nucleobases. For example, |
None
|
complementary |
bool
|
Whether to mutate the complementary strand. Defaults to True. |
True
|
frame |
int
|
The frame to mutate. Defaults to -1. |
-1
|
verbose |
bool
|
Whether to print the mutated sequence. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If no mutation dictionary is provided. |
Notes
- Valid nucleobases for mutations include:
- Canonical bases: A, T, G, C, U
- Hachimoji: B [A_ana], S [T_ana], P [C_ana], Z [G_ana] (DOI: 10.1126/science.aat0971)
- Fluorescent: 2-aminopurine 2AP (E), triC (D) (DOI: 10.1002/anie.201001312), tricyclic cytosine base analogue (1tuq)
- Hydrophobic pairs: d5SICS (L), dNaM (M)
Example
Create a DNA object
Source code in mdna/nucleic.py
save_pdb(filename=None, frame=-1)
¶
Save the DNA structure as a pdb file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Filename to save the pdb file. Defaults to None. |
None
|
frame |
int
|
If the trajectory has multiple frames, specify the frame to save. Defaults to -1. |
-1
|