Skip to content

Commit 785c146

Browse files
committed
rna_pdb_tools.py: add conect for rpr file
1 parent c742140 commit 785c146

File tree

2 files changed

+150
-1
lines changed

2 files changed

+150
-1
lines changed

rna_tools/rna_pdb_tools.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def get_parser():
7070
parser.add_argument('--renum-nmr', help='',
7171
action='store_true')
7272

73+
parser.add_argument('--conect', help='add conect to rpr file', action='store_true')
74+
7375
parser.add_argument('--renum-residues-dirty', help='', action='store_true')
7476

7577
parser.add_argument('--undo', help='undo operation of action done --inplace, , rename "backup files" .pdb~ to pdb, ALL files in the folder, not only ~ related to the last action (that you might want to revert, so be careful)', action='store_true')
@@ -512,7 +514,7 @@ def get_parser():
512514
ignore_op3 = False
513515
if args.mdr:
514516
ignore_op3 = True
515-
517+
516518
remarks = s.get_rnapuzzle_ready(args.renumber_residues, fix_missing_atoms=fix_missing_atom,
517519
rename_chains=rename_chains,
518520
report_missing_atoms=report_missing_atoms,
@@ -524,6 +526,7 @@ def get_parser():
524526
ignore_op3=ignore_op3,
525527
save_single_res=args.save_single_res,
526528
ref_frame_only = args.ref_frame_only,
529+
conect=args.conect,
527530
verbose=args.verbose)
528531

529532
if args.inplace:

rna_tools/rna_tools_lib.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,140 @@
3535
"HIS", "ILE", "LEU", "LYS", "MET", "PHE", "PRO", "SER", "THR",
3636
"TRP", "TYR", "VAL"]
3737

38+
def generate_conect_records(residue_type, shift=0):
39+
"""
40+
Generate CONECT records for an RNA residue (U, A, C, or G).
41+
42+
Args:
43+
residue_type (str): Type of residue ('U', 'A', 'C', or 'G').
44+
shift (int): Value to shift all atom serial numbers by.
45+
46+
Returns:
47+
list: List of CONECT records as strings.
48+
"""
49+
# Define connections for each residue type
50+
if residue_type == "U":
51+
connections = [
52+
(1, 2), # P -> OP1
53+
(1, 3), # P -> OP2
54+
(1, 4), # P -> O5'
55+
(4, 5), # O5' -> C5'
56+
(5, 6), # C5' -> C4'
57+
(6, 7), # C4' -> O4'
58+
(6, 8), # C4' -> C3'
59+
(8, 9), # C3' -> O3'
60+
(8, 10), # C3' -> C2'
61+
(10, 11), # C2' -> O2'
62+
(10, 12), # C2' -> C1'
63+
(12, 13), # C1' -> N1
64+
(13, 14), # N1 -> C2
65+
(14, 15), # C2 -> O2
66+
(14, 16), # C2 -> N3
67+
(16, 17), # N3 -> C4
68+
(17, 18), # C4 -> O4
69+
(17, 19), # C4 -> C5
70+
(19, 20), # C5 -> C6
71+
(20, 13), # C6 -> N1
72+
(7, 12), # O4' -> C1'
73+
(9, 21) # junction
74+
]
75+
elif residue_type == "A":
76+
connections = [
77+
(1, 2), # P -> OP1
78+
(1, 3), # P -> OP2
79+
(1, 4), # P -> O5'
80+
(4, 5), # O5' -> C5'
81+
(5, 6), # C5' -> C4'
82+
(6, 7), # C4' -> O4'
83+
(6, 8), # C4' -> C3'
84+
(8, 9), # C3' -> O3'
85+
(8, 10), # C3' -> C2'
86+
(10, 11), # C2' -> O2'
87+
(10, 12), # C2' -> C1'
88+
(12, 13), # C1' -> N9
89+
(13, 14), # N9 -> C8
90+
(14, 15), # C8 -> N7
91+
(15, 16), # N7 -> C5
92+
(16, 17), # C5 -> C6
93+
(17, 18), # C6 -> N6
94+
(17, 19), # C6 -> N1
95+
(19, 20), # N1 -> C2
96+
(20, 21), # C2 -> N3
97+
(21, 22), # N3 -> C4
98+
(22, 16), # C4 -> C5
99+
(22, 13), # C4 -> N9
100+
(7, 12), # O4' -> C1'
101+
(9, 23) # junction
102+
]
103+
elif residue_type == "C":
104+
connections = [
105+
(1, 2), # P -> OP1
106+
(1, 3), # P -> OP2
107+
(1, 4), # P -> O5'
108+
(4, 5), # O5' -> C5'
109+
(5, 6), # C5' -> C4'
110+
(6, 7), # C4' -> O4'
111+
(6, 8), # C4' -> C3'
112+
(8, 9), # C3' -> O3'
113+
(8, 10), # C3' -> C2'
114+
(10, 11), # C2' -> O2'
115+
(10, 12), # C2' -> C1'
116+
(12, 13), # C1' -> N1
117+
(13, 14), # N1 -> C2
118+
(14, 15), # C2 -> O2
119+
(14, 16), # C2 -> N3
120+
(16, 17), # N3 -> C4
121+
(17, 18), # C4 -> N4
122+
(17, 19), # C4 -> C5
123+
(19, 20), # C5 -> C6
124+
(20, 13), # C6 -> N1
125+
(7, 12), # O4' -> C1' (additional connection)
126+
(9, 21) # junction
127+
]
128+
elif residue_type == "G":
129+
connections = [
130+
(1, 2), # P -> OP1
131+
(1, 3), # P -> OP2
132+
(1, 4), # P -> O5'
133+
(4, 5), # O5' -> C5'
134+
(5, 6), # C5' -> C4'
135+
(6, 7), # C4' -> O4'
136+
(6, 8), # C4' -> C3'
137+
(8, 9), # C3' -> O3'
138+
(8, 10), # C3' -> C2'
139+
(10, 11), # C2' -> O2'
140+
(10, 12), # C2' -> C1'
141+
(12, 13), # C1' -> N9
142+
(13, 14), # N9 -> C8
143+
(14, 15), # C8 -> N7
144+
(15, 16), # N7 -> C5
145+
(16, 17), # C5 -> C6
146+
(17, 18), # C6 -> O6
147+
(17, 19), # C6 -> N1
148+
(19, 20), # N1 -> C2
149+
(20, 21), # C2 -> N2
150+
(20, 22), # C2 -> N3
151+
(22, 23), # N3 -> C4
152+
(23, 16), # C4 -> C5
153+
(23, 13), # C4 -> N9
154+
(7, 12), # O4' -> C1' (additional connection)
155+
(9, 24) # junction
156+
]
157+
else:
158+
raise ValueError("Invalid residue type. Choose 'U', 'A', 'C', or 'G'.")
159+
160+
# Generate CONECT records with shifted serial numbers
161+
conect_records = []
162+
for conn in connections:
163+
atom1_serial, atom2_serial = conn
164+
# Shift the serial numbers
165+
atom1_serial += shift
166+
atom2_serial += shift
167+
conect_records.append(f"CONECT{atom1_serial:>4}{atom2_serial:>4}")
168+
169+
return conect_records
170+
171+
38172
def aa3to1(aaa):
39173
"""based on https://pymolwiki.org/index.php/Aa_codes"""
40174
if len(aaa) != 3: # aaa is 'G', like for RNA ;-)
@@ -1256,6 +1390,7 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
12561390
ref_frame_only = False,
12571391
p_only = False,
12581392
check_geometry = False,
1393+
conect = False,
12591394
verbose=False): # :, ready_for="RNAPuzzle"):
12601395
"""Get rnapuzzle (SimRNA) ready structure.
12611396
@@ -1430,6 +1565,8 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
14301565
c = 1 # new chain, goes from 1 !!! if renumber True
14311566
prev_r = '' # init prev_r
14321567

1568+
conects = []
1569+
atom_index = 0
14331570
for r in res:
14341571
#
14351572
# deal with heteratm
@@ -1825,6 +1962,13 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
18251962
io.set_structure(structure)
18261963
io.save(f"{self.fn}_{r2.id[1]}.pdb")
18271964

1965+
# add CONET
1966+
if conect:
1967+
ic(atom_index, r2)
1968+
conects.extend(generate_conect_records(r2.get_resname().strip(), atom_index)) # + '\n'
1969+
atom_index += len(r2)
1970+
print(conect)
1971+
18281972
prev_r = r # hack to keep preview residue to be used in the function
18291973
# e.g., to get an atom from this residue
18301974
c += 1
@@ -1896,6 +2040,8 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
18962040
nlines.append(l)
18972041
c += 1
18982042
self.lines = nlines
2043+
if conect:
2044+
self.lines += conects
18992045
return remarks
19002046

19012047
def set_occupancy_atoms(self, occupancy):

0 commit comments

Comments
 (0)