Skip to content

Commit

Permalink
proper bonds for old topology
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed Nov 27, 2024
1 parent 7d013d3 commit e3a215c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 20 additions & 8 deletions molecularnodes/entities/trajectory/oxdna/OXDNAParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ def _parseatoms(self):
with open(self.filename) as f:
first_line = f.readline()

dimensions = np.array(first_line.split(), dtype=int)
n_atoms = dimensions[0]

array = np.loadtxt(self.filename, skiprows=1, max_rows=n_atoms, dtype=str)
is_new_topology = "5->3" in first_line

if not is_new_topology:
dimensions = np.array(first_line.split(), dtype=int)
n_atoms = dimensions[0]
array = np.loadtxt(self.filename, skiprows=1, max_rows=n_atoms, dtype=str)

# each topology item has two bond columns, which say what the base is bonded
# from and what it is bonded to. -1 means it is not bonded
# we need to turn that into an array of bond pairs
bond_idx = np.zeros((n_atoms * 2, 2), int)
row_numbers = np.arange(n_atoms, dtype=int)
for i in range(2):
rows = row_numbers + (i * n_atoms)
bond_idx[rows, 0] = array[:, (i + 2)]
bond_idx[rows, 1] = row_numbers

# drop any that have -1 as they aren't bonded to anything
mask = np.logical_and(bond_idx[:, 0] != -1, bond_idx[:, 1] != -1)
bond_idx = bond_idx[mask, :]

attrs = []
idx = np.arange(1, n_atoms + 1, dtype=int)
Expand All @@ -35,10 +51,6 @@ def _parseatoms(self):

topo = Topology(n_atoms, n_atoms, 1, attrs=attrs)

bond_idx = array[:, 2:].astype(int)
mask = np.logical_and(bond_idx[:, 0] != -1, bond_idx[:, 1] != -1)
bond_idx = bond_idx[mask, :]

bonds = Bonds(bond_idx)
topo.add_TopologyAttr(bonds)

Expand Down
2 changes: 0 additions & 2 deletions tests/test_dna.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np
import molecularnodes as mn
import pytest
import MDAnalysis as mda
from molecularnodes.entities.trajectory import dna
Expand Down

0 comments on commit e3a215c

Please sign in to comment.