Geometry Classes¶
Classes for computing nucleobase reference frames and rigid base parameters.
Reference Base Class¶
Fits a reference frame to a single nucleobase using the Tsukuba convention.
mdna.geometry.ReferenceBase
¶
Compute a nucleobase reference frame following the Tsukuba convention.
Given an MDTraj trajectory for a single residue, this class identifies the base type (purine, pyrimidine, or non-canonical analogue), locates the key atoms (C1', N-glycosidic nitrogen, and a ring carbon), and calculates the local reference frame vectors (origin b_R, long axis b_L, short axis b_D, and normal b_N).
Attributes:
| Name | Type | Description |
|---|---|---|
traj |
Trajectory
|
Single-residue trajectory. |
base_type |
str
|
One-letter nucleobase code (e.g. |
b_R |
ndarray
|
Reference point (origin) of shape |
b_L |
ndarray
|
Long-axis unit vector of shape |
b_D |
ndarray
|
Short-axis unit vector of shape |
b_N |
ndarray
|
Base-normal unit vector of shape |
Source code in mdna/geometry.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 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 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 | |
__init__(traj)
¶
Initialize the reference base calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj
|
Trajectory
|
MDTraj trajectory containing a single nucleotide residue. |
required |
Source code in mdna/geometry.py
calculate_base_frame()
¶
Calculate the base reference frame from the Tsukuba convention.
Computes the base-normal (b_N) from the cross product of key atom vectors, then derives the reference point (b_R), long axis (b_L), and short axis (b_D) by rotating the N→C1' vector.
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Array of shape |
Source code in mdna/geometry.py
get_base_type()
¶
Determine the nucleobase type from the atoms present in the trajectory.
Matches the set of non-hydrogen atom names against the known nucleobase dictionaries for canonical and non-canonical bases.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no known base type matches the atom set. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Single-letter nucleobase code (e.g. |
Source code in mdna/geometry.py
get_coordinates()
¶
Retrieve C1', N-glycosidic, and ring-carbon coordinates for the base.
The specific atoms selected depend on the base type (purine vs pyrimidine vs non-canonical analogue).
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]:
|
Source code in mdna/geometry.py
plot_baseframe(atoms=True, frame=True, ax=None, length=1)
¶
Plot the nucleobase atoms and/or reference frame vectors in 3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atoms
|
bool
|
If True, scatter-plot the atom positions. Defaults to True. |
True
|
frame
|
bool
|
If True, draw quiver arrows for the b_L, b_D, and b_N vectors. Defaults to True. |
True
|
ax
|
Axes
|
Existing 3D axes to draw on. If None, a new figure is created. |
None
|
length
|
int
|
Length scale for the quiver arrows. Defaults to 1. |
1
|
Source code in mdna/geometry.py
Rigid Base Parameter Class¶
Computes inter- and intra-base pair parameters from an MDTraj trajectory.
mdna.geometry.NucleicFrames
¶
Rigid base-pair parameter computation from DNA trajectories.
Extracts nucleobase reference frames from an MDTraj trajectory using the Tsukuba convention, then computes the six intra-base-pair parameters (shear, stretch, stagger, buckle, propeller, opening) and six inter-base-pair step parameters (shift, slide, rise, tilt, roll, twist) for every frame in the trajectory.
The mean base-pair reference frames are also stored and can be used as input for downstream construction or analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
traj |
Trajectory
|
Input trajectory. |
frames |
ndarray
|
Mean reference frames of shape |
parameters |
ndarray
|
Combined base-pair and step parameters of shape
|
bp_params |
ndarray
|
Intra-base-pair parameters of shape |
step_params |
ndarray
|
Inter-base-pair step parameters of shape |
names |
list[str]
|
Parameter names (base + step). |
Example
Source code in mdna/geometry.py
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 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 | |
__init__(traj, chainids=[0, 1], fit_reference=False)
¶
Initialize the NucleicFrames object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj
|
object
|
MDtraj trajectory object. |
required |
chainids
|
list
|
Chainids of sense- and anti-sense strands. Defaults to [0,1]. |
[0, 1]
|
fit_reference
|
bool
|
Fit each base to canonical reference bases before frame extraction. Defaults to False. |
False
|
Source code in mdna/geometry.py
analyse_frames()
¶
Compute base-pair and step parameters from the extracted reference frames.
Populates bp_params, step_params, parameters, frames,
and names attributes.
Source code in mdna/geometry.py
calculate_parameters(frames_A, frames_B, is_step=False)
¶
Calculate the parameters between each base pair and mean reference frames.
Assumes frames are of shape (n_frames, n_residues, 4, 3) where the last two dimensions are the base triads. The base triads consist of an origin (first index) and three vectors (latter 3 indices) representing the base frame. With the order of the vectors being: b_R, b_L, b_D, b_N.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames_A
|
ndarray
|
Frames of shape (n_frames, n_residues, 4, 3) representing the base triads for chain A. |
required |
frames_B
|
ndarray
|
Frames of shape (n_frames, n_residues, 4, 3) representing the base triads for chain B. |
required |
is_step
|
bool
|
Flag indicating if the input is a single step or a trajectory. Defaults to False. |
False
|
Notes
Note the vectors are stored rowwise in the base triads, and not the usual column representation of the rotation matrices.
Returns:
| Name | Type | Description |
|---|---|---|
params |
ndarray
|
The parameters of shape (n_frames, n_residues, 6) representing the relative translation and rotation between each base pair. |
mean_reference_frames |
ndarray
|
The mean reference frames of shape (n_bp, n_frames, 4, 3) representing the mean reference frame of each base pair. |
Source code in mdna/geometry.py
compute_parameters(rotation_A, rotation_B, origin_A, origin_B)
¶
Calculate the parameters between each base pair and mean reference frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation_A
|
ndarray
|
Rotation matrices of shape (n, 3, 3) for the first triad. |
required |
rotation_B
|
ndarray
|
Rotation matrices of shape (n, 3, 3) for the second triad. |
required |
origin_A
|
ndarray
|
Origins of shape (n, 3) for the first triad. |
required |
origin_B
|
ndarray
|
Origins of shape (n, 3) for the second triad. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rigid_parameters |
ndarray
|
The parameters of shape (n, 12) representing the relative translation and rotation between each base pair. |
trans_mid |
ndarray
|
The mean translational vector of shape (n, 3) between the triads. |
rotation_mid |
ndarray
|
The mean rotation matrix of shape (n, 3, 3) between the triads. |
Source code in mdna/geometry.py
get_base_reference_frames()
¶
Compute reference frames for all residues in both strands.
Returns:
| Name | Type | Description |
|---|---|---|
frames |
dict
|
Mapping of MDTraj Residue to base vectors array of shape |
Source code in mdna/geometry.py
get_base_vectors(res)
¶
Compute base reference vectors for a single residue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
Trajectory
|
Single-residue trajectory slice. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
vectors |
ndarray
|
Base vectors of shape |
Source code in mdna/geometry.py
get_parameter(name='twist')
¶
Get a single named parameter across all frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name. One of: shear, stretch, stagger, buckle, propeller, opening, shift, slide, rise, tilt, roll, twist. |
'twist'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Parameter values of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the parameter name is not recognised. |
Source code in mdna/geometry.py
get_parameters(step=False, base=False)
¶
Return computed rigid base parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
bool
|
If True, return only step parameters. |
False
|
base
|
bool
|
If True, return only base-pair parameters. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
tuple[ndarray, list[str]]
|
Parameters of shape
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both step and base are True. |
Source code in mdna/geometry.py
get_residues(chain_index, reverse=False)
¶
Get residues from a specified chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_index
|
int
|
Index of the chain in the topology. |
required |
reverse
|
bool
|
If True, return residues in reverse order (used for the anti-sense strand). |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
residues |
list
|
MDTraj Residue objects. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If chain_index is out of range. |
Source code in mdna/geometry.py
load_reference_bases()
¶
Load canonical reference base structures from bundled HDF5 files.
Returns:
| Name | Type | Description |
|---|---|---|
bases |
dict[str, Trajectory]
|
Mapping of base letter (A, C, G, T) to single-frame trajectory. |
Source code in mdna/geometry.py
plot_parameters(fig=None, ax=None, mean=True, std=True, figsize=[10, 3.5], save=False, step=True, base=True, base_color='cornflowerblue', step_color='coral')
¶
Plot the rigid base parameters of the DNA structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Existing figure. |
None
|
ax
|
ndarray
|
Array of axes to plot on. |
None
|
mean
|
bool
|
Plot the mean line. |
True
|
std
|
bool
|
Plot the standard deviation band. |
True
|
figsize
|
list
|
Figure size |
[10, 3.5]
|
save
|
bool
|
If True, save the figure to |
False
|
step
|
bool
|
Include step parameters. |
True
|
base
|
bool
|
Include base-pair parameters. |
True
|
base_color
|
str
|
Color for base-pair parameter plots. |
'cornflowerblue'
|
step_color
|
str
|
Color for step parameter plots. |
'coral'
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
tuple
|
|
Source code in mdna/geometry.py
reshape_input(input_A, input_B, is_step=False)
¶
Reshape the input to the correct format for the calculations.
Args: input_A (ndarray): Input array for the first triad. input_B (ndarray): Input array for the second triad. is_step (bool, optional): Flag indicating if the input is a single step or a trajectory. Defaults to False.
Returns: rotation_A (ndarray): Rotation matrices of shape (n, 3, 3) for the first triad. rotation_B (ndarray): Rotation matrices of shape (n, 3, 3) for the second triad. origin_A (ndarray): Origins of shape (n, 3) for the first triad. origin_B (ndarray): Origins of shape (n, 3) for the second triad. original_shape (tuple): The original shape of the input.