|
35 | 35 | "HIS", "ILE", "LEU", "LYS", "MET", "PHE", "PRO", "SER", "THR",
|
36 | 36 | "TRP", "TYR", "VAL"]
|
37 | 37 |
|
| 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 | + |
38 | 172 | def aa3to1(aaa):
|
39 | 173 | """based on https://pymolwiki.org/index.php/Aa_codes"""
|
40 | 174 | 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,
|
1256 | 1390 | ref_frame_only = False,
|
1257 | 1391 | p_only = False,
|
1258 | 1392 | check_geometry = False,
|
| 1393 | + conect = False, |
1259 | 1394 | verbose=False): # :, ready_for="RNAPuzzle"):
|
1260 | 1395 | """Get rnapuzzle (SimRNA) ready structure.
|
1261 | 1396 |
|
@@ -1430,6 +1565,8 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
|
1430 | 1565 | c = 1 # new chain, goes from 1 !!! if renumber True
|
1431 | 1566 | prev_r = '' # init prev_r
|
1432 | 1567 |
|
| 1568 | + conects = [] |
| 1569 | + atom_index = 0 |
1433 | 1570 | for r in res:
|
1434 | 1571 | #
|
1435 | 1572 | # deal with heteratm
|
@@ -1825,6 +1962,13 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
|
1825 | 1962 | io.set_structure(structure)
|
1826 | 1963 | io.save(f"{self.fn}_{r2.id[1]}.pdb")
|
1827 | 1964 |
|
| 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 | + |
1828 | 1972 | prev_r = r # hack to keep preview residue to be used in the function
|
1829 | 1973 | # e.g., to get an atom from this residue
|
1830 | 1974 | c += 1
|
@@ -1896,6 +2040,8 @@ def get_rnapuzzle_ready(self, renumber_residues=True, fix_missing_atoms=True,
|
1896 | 2040 | nlines.append(l)
|
1897 | 2041 | c += 1
|
1898 | 2042 | self.lines = nlines
|
| 2043 | + if conect: |
| 2044 | + self.lines += conects |
1899 | 2045 | return remarks
|
1900 | 2046 |
|
1901 | 2047 | def set_occupancy_atoms(self, occupancy):
|
|
0 commit comments