biobb-structure-checking 3.16.3__tar.gz → 3.16.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {biobb_structure_checking-3.16.3/biobb_structure_checking.egg-info → biobb_structure_checking-3.16.4}/PKG-INFO +2 -2
  2. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/README.md +1 -1
  3. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/backbone.py +4 -3
  4. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/getss.py +3 -2
  5. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/sequences.py +12 -10
  6. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/constants.py +9 -1
  7. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/dat/commands.hlp +2 -0
  8. biobb_structure_checking-3.16.4/biobb_structure_checking/modeller_manager.py +250 -0
  9. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/sequencedata.py +26 -27
  10. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/utils.py +6 -3
  11. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/structure_checking.py +2 -1
  12. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/structure_manager.py +76 -24
  13. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4/biobb_structure_checking.egg-info}/PKG-INFO +2 -2
  14. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking.egg-info/SOURCES.txt +0 -5
  15. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/setup.py +1 -1
  16. biobb_structure_checking-3.16.3/biobb_structure_checking/dat/modRes/modSER.json +0 -361
  17. biobb_structure_checking-3.16.3/biobb_structure_checking/dat/modRes/modTHR.json +0 -135
  18. biobb_structure_checking-3.16.3/biobb_structure_checking/dat/modRes/modTYR.json +0 -366
  19. biobb_structure_checking-3.16.3/biobb_structure_checking/dat/modRes/modres.json +0 -7705
  20. biobb_structure_checking-3.16.3/biobb_structure_checking/dat/modRes/modres_phospho.json +0 -7705
  21. biobb_structure_checking-3.16.3/biobb_structure_checking/modeller_manager.py +0 -176
  22. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/LICENSE +0 -0
  23. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/MANIFEST.in +0 -0
  24. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/__init__.py +0 -0
  25. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/check_structure.py +0 -0
  26. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/__init__.py +0 -0
  27. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/add_hydrogen.py +0 -0
  28. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/altloc.py +0 -0
  29. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/amide.py +0 -0
  30. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/chains.py +0 -0
  31. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/chiral.py +0 -0
  32. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/chiral_bck.py +0 -0
  33. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/cistransbck.py +0 -0
  34. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/clashes.py +0 -0
  35. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/fixside.py +0 -0
  36. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/inscodes.py +0 -0
  37. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/ligands.py +0 -0
  38. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/metals.py +0 -0
  39. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/models.py +0 -0
  40. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/mutateside.py +0 -0
  41. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/rem_hydrogen.py +0 -0
  42. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/commands/water.py +0 -0
  43. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/dat/ADT_prm.json +0 -0
  44. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/dat/CMIP_prm.json +0 -0
  45. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/dat/all_residues.in +0 -0
  46. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/dat/data_lib.json +0 -0
  47. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/libs/__init__.py +0 -0
  48. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/libs/data_lib_manager.py +0 -0
  49. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/libs/residue_lib_manager.py +0 -0
  50. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/__init__.py +0 -0
  51. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/chainsdata.py +0 -0
  52. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/modelsdata.py +0 -0
  53. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/residue_set.py +0 -0
  54. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/modelling/structuredata.py +0 -0
  55. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/mutation_manager.py +0 -0
  56. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/pdbio/PDBIO_extended.py +0 -0
  57. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/pdbio/__init__.py +0 -0
  58. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/pdbio/bare_builder.py +0 -0
  59. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/pdbio/json_writer.py +0 -0
  60. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/pdbio/mmb_server.py +0 -0
  61. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/pdbio/param_input.py +0 -0
  62. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking/py.typed +0 -0
  63. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking.egg-info/dependency_links.txt +0 -0
  64. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking.egg-info/entry_points.txt +0 -0
  65. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking.egg-info/requires.txt +0 -0
  66. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/biobb_structure_checking.egg-info/top_level.txt +0 -0
  67. {biobb_structure_checking-3.16.3 → biobb_structure_checking-3.16.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: biobb_structure_checking
3
- Version: 3.16.3
3
+ Version: 3.16.4
4
4
  Summary: BioBB_structure_checking performs MDWeb structure checking tool set as a command line utility.
5
5
  Home-page: https://github.com/bioexcel/biobb_structure_checking
6
6
  Author: Biobb developers
@@ -57,7 +57,7 @@ The latest documentation of this package can be found in our readthedocs site:
57
57
  [latest package documentation](http://biobb-structure-checking.readthedocs.io/en/latest/).
58
58
 
59
59
  ### Version
60
- v3.16.3 Aug 2026
60
+ v3.16.4 Oct 2026
61
61
 
62
62
  ### Requirements
63
63
 
@@ -23,7 +23,7 @@ The latest documentation of this package can be found in our readthedocs site:
23
23
  [latest package documentation](http://biobb-structure-checking.readthedocs.io/en/latest/).
24
24
 
25
25
  ### Version
26
- v3.16.3 Aug 2026
26
+ v3.16.4 Oct 2026
27
27
 
28
28
  ### Requirements
29
29
 
@@ -115,7 +115,8 @@ def fix(strcheck, opts, fix_data=None):
115
115
  opts['fix_chain'],
116
116
  fix_data['bck_breaks_list'],
117
117
  strcheck.args['modeller_key'],
118
- opts['extra_gap']
118
+ opts['extra_gap'],
119
+ bool(opts['fix_known'])
119
120
  )
120
121
  if not fixed_main:
121
122
  fix_done = True
@@ -183,7 +184,7 @@ def fix(strcheck, opts, fix_data=None):
183
184
  return False
184
185
 
185
186
 
186
- def _backbone_fix_main_chain(strcheck, fix_main_bck, breaks_list, modeller_key, extra_gap):
187
+ def _backbone_fix_main_chain(strcheck, fix_main_bck, breaks_list, modeller_key, extra_gap, fix_known=False):
187
188
  print("Main chain fixes")
188
189
 
189
190
  brk_rnums = [
@@ -247,7 +248,7 @@ def _backbone_fix_main_chain(strcheck, fix_main_bck, breaks_list, modeller_key,
247
248
  if f"({mu.residue_num(rpair[0])}-{mu.residue_num(rpair[1])})".replace(' ', '')\
248
249
  in fix_main_bck.split(',') or input_option == 'all'
249
250
  ]
250
- return strcheck.strucm.fix_backbone_chain(to_fix, modeller_key, extra_gap)
251
+ return strcheck.strucm.fix_backbone_chain(to_fix, modeller_key, extra_gap, fix_known)
251
252
 
252
253
 
253
254
  def _backbone_add_caps(strcheck, add_caps, bck_breaks_list):
@@ -1,5 +1,6 @@
1
1
  """ Module supporting getss command"""
2
2
 
3
+ from numpy import sqrt
3
4
  import biobb_structure_checking.constants as cts
4
5
  import biobb_structure_checking.modelling.utils as mu
5
6
  from biobb_structure_checking.pdbio.param_input import ParamInput
@@ -21,12 +22,12 @@ def check(strcheck):
21
22
  print(
22
23
  f" {mu.atom_id(ssb[0]):12}"
23
24
  f" {mu.atom_id(ssb[1]):12}"
24
- f" {ssb[2]:8.3f}"
25
+ f" {sqrt(ssb[2]):8.3f}"
25
26
  )
26
27
  strcheck.summary['getss']['found'].append({
27
28
  'at1': mu.atom_id(ssb[0]),
28
29
  'at2': mu.atom_id(ssb[1]),
29
- 'dist': round(float(ssb[2]), 4)
30
+ 'dist': round(sqrt(float(ssb[2])), 4)
30
31
  })
31
32
  return SS_bonds
32
33
 
@@ -21,16 +21,18 @@ def check(strcheck):
21
21
  'canonical': can_seq,
22
22
  'structure': pdb_seq
23
23
  }
24
- mismatches = strcheck.strucm.sequence_data.compare_sequences(strcheck.strucm)
25
- if mismatches:
26
- print(f"Found {len(mismatches)} mismatch(es)")
27
- for chain_id, mismatch in mismatches.items():
28
- print(
29
- f"Chain {chain_id}\n"
30
- f"{mismatch['canonical']}\n"
31
- f"{mismatch['structure']}"
32
- )
33
- strcheck.summary['sequence_mismatches'] = mismatches
24
+ if strcheck.strucm.sequence_data.has_canonical[0]:
25
+ mismatches = strcheck.strucm.sequence_data.compare_sequences(strcheck.strucm)
26
+
27
+ if mismatches:
28
+ print(f"Found {len(mismatches)} mismatch(es)")
29
+ for ch_id, mismatch in mismatches.items():
30
+ print(
31
+ f"Chain {ch_id}\n"
32
+ f"{mismatch['canonical']}\n"
33
+ f"{mismatch['structure']}"
34
+ )
35
+ strcheck.summary['sequence_mismatches'] = mismatches
34
36
  return fasta
35
37
 
36
38
 
@@ -8,7 +8,7 @@ from os.path import join as opj
8
8
 
9
9
  from biobb_structure_checking.pdbio.param_input import Dialog
10
10
 
11
- VERSION = '3.16.3'
11
+ VERSION = '3.16.4'
12
12
 
13
13
  # Default locations and settings
14
14
  DATA_DIR_DEFAULT_PATH = 'dat'
@@ -518,6 +518,14 @@ DIALOGS.add_option(
518
518
  'Replace extra_gap additional flanking residues',
519
519
  int
520
520
  )
521
+ DIALOGS.add_option(
522
+ 'backbone',
523
+ '--fix_known',
524
+ 'fix_known',
525
+ 'Optimize only the missing residues with Modeller, '
526
+ 'the residues in the structure keep their coordinates',
527
+ 'bool'
528
+ )
521
529
  DIALOGS.add_option(
522
530
  'backbone',
523
531
  '--no_recheck',
@@ -70,6 +70,7 @@ backbone [--fix_atoms All|None|Residue List]
70
70
  [--fix_chain All|None|Break list]
71
71
  [--add_caps All|None|Break list]
72
72
  [--extra_gap]
73
+ [--fix_known]
73
74
  [--no_recheck]
74
75
  [--no_check_clashes]
75
76
  Analyze main chain missing atoms and fragments (protein only).
@@ -77,6 +78,7 @@ backbone [--fix_atoms All|None|Residue List]
77
78
  --fix_chain Missing fragments filled using comparative modelling (Modeller License needed)
78
79
  --add_caps Adds ACE and NME residues as necessary, preserving existing atoms
79
80
  --extra_gap Recovers additional residues from model either side of the break, helps to fix loop connections (experimental)
81
+ --fix_known Optimizes only the missing residues with Modeller, the residues in the structure keep their coordinates
80
82
  Rechecks beckbone on each op unless --no_recheck is set.
81
83
  Generated clashes are checked unless --no_check_clashes
82
84
 
@@ -0,0 +1,250 @@
1
+ """
2
+ Module to handle an interface to modeller,
3
+ used to rebuild main and side chains and
4
+ to optimize side chain orientation
5
+ """
6
+
7
+ import re
8
+ import sys
9
+ import os
10
+ from os.path import join as opj
11
+ import uuid
12
+ import shutil
13
+
14
+ import Bio
15
+ OLD_ALIGN = Bio.__version__ < '1.79'
16
+ from Bio import SeqIO
17
+ if OLD_ALIGN:
18
+ from Bio import pairwise2
19
+ from Bio.Seq import Seq
20
+ from Bio.SeqRecord import SeqRecord
21
+ # Check for back-compatiblity with biopython < 1.77
22
+ try:
23
+ from Bio.Seq import IUPAC
24
+ has_IUPAC = True
25
+ except ImportError:
26
+ has_IUPAC = False
27
+
28
+ try:
29
+ from modeller import Environ, Selection, log
30
+ from modeller.automodel import AutoModel, assess
31
+ except ImportError:
32
+ sys.exit("Error importing Modeller package")
33
+
34
+ from biobb_structure_checking.modelling.utils import PROTEIN
35
+
36
+ TMP_BASE_DIR = '/tmp'
37
+ DEBUG = False
38
+
39
+
40
+ class ModellerManager():
41
+ """
42
+ | modeller_manager ModellerManager
43
+ | Class to handle Modeller calculations """
44
+ def __init__(self):
45
+ self.ch_id = ''
46
+ self.sequences = None
47
+ self.templ_file = 'templ.pdb'
48
+ if not DEBUG:
49
+ self.tmpdir = opj(TMP_BASE_DIR, "mod" + str(uuid.uuid4()))
50
+ try:
51
+ os.mkdir(self.tmpdir)
52
+ except IOError as err:
53
+ sys.exit(err)
54
+ else:
55
+ self.tmpdir = "/tmp/modtest"
56
+ print("Using temporary working dir " + self.tmpdir)
57
+
58
+ self.env = Environ()
59
+
60
+ self.env.io.atom_files_directory = [self.tmpdir]
61
+ log.none()
62
+
63
+ def build(self, target_model, target_chain, extra_NTerm_res, fix_known=False):
64
+ """ ModellerManager.build
65
+ Prepare Modeller input and builds the model
66
+
67
+ Args:
68
+ target_model (int) : Model to repair
69
+ target_chain (str) : Chain to repair
70
+ extra_NTerm_res (int) : Number of additional residues
71
+ at NTerm (to fix NTerm, experimental)
72
+ fix_known (bool) : Optimize only the missing internal segments, the
73
+ residues in the structure keep their coordinates. The other protein
74
+ chains join the model too, so the segments are rebuilt around them
75
+ """
76
+ alin_file = opj(self.tmpdir, "alin.pir")
77
+
78
+ if target_chain not in self.sequences.has_canonical[target_model]:
79
+ raise NoCanSeqError(target_model, target_chain)
80
+
81
+ tgt_seq = self.sequences.data[target_model][target_chain]['can'].seq
82
+
83
+ # triming N-term of canonical seq
84
+ pdb_seq = self.sequences.data[target_model][target_chain]['pdb']['frgs'][0].seq
85
+ nt_pos = max(tgt_seq.find(pdb_seq) - extra_NTerm_res, 0)
86
+ tgt_seq = tgt_seq[nt_pos:]
87
+
88
+
89
+ # TODO trim trailing residues in tgt_seq
90
+
91
+ templs = []
92
+ knowns = []
93
+ gaps = []
94
+ for ch_id in self.sequences.data[target_model][target_chain]['chains']:
95
+ frgs = self.sequences.data[target_model][ch_id]['pdb']['frgs']
96
+ pdb_seq = frgs[0].seq
97
+ for i in range(1, len(frgs)):
98
+ frag_seq = frgs[i].seq
99
+ pdb_seq += frag_seq
100
+ # tuned to open gaps on missing loops only
101
+
102
+ # The chain to fix is placed according to the canonical position of its
103
+ # fragments, an alignment may shift the gaps in low complexity regions
104
+ aligned_seq = None
105
+ if ch_id == target_chain:
106
+ aligned_seq = _place_fragments(frgs, len(tgt_seq), nt_pos)
107
+ if aligned_seq is None:
108
+ if not OLD_ALIGN:
109
+ alin = self.sequences.aligner.align(tgt_seq, pdb_seq)
110
+ else:
111
+ alin = pairwise2.align.globalxs(tgt_seq, pdb_seq, -5, -1)
112
+ aligned_seq = alin[0][1]
113
+
114
+ if has_IUPAC:
115
+ pdb_seq = Seq(aligned_seq, IUPAC.protein)
116
+ else:
117
+ pdb_seq = Seq(aligned_seq)
118
+
119
+ if ch_id == target_chain:
120
+ # (first, last) residues of every internal gap
121
+ gaps = [(m.start() + 1, m.end()) for m in re.finditer('-+', str(pdb_seq))
122
+ if 0 < m.start() and m.end() < len(pdb_seq)]
123
+
124
+ templs.append(_template(pdb_seq, f'templ{ch_id}', self.templ_file, ch_id, frgs))
125
+ knowns.append(f'templ{ch_id}')
126
+
127
+ if ch_id == target_chain:
128
+ tgt_seq = tgt_seq[0:len(pdb_seq)]
129
+
130
+ if fix_known:
131
+ # The other protein chains join the model, one segment and one template
132
+ # each, so the gaps, the only residues that move, are rebuilt around them.
133
+ # The file is saved before any chain is fixed: their own gaps stay open
134
+ others = [(ch_id, data['pdb']['frgs'])
135
+ for ch_id, data in self.sequences.data[target_model].items()
136
+ if ch_id != target_chain and data.get('pdb', {}).get('type') == PROTEIN]
137
+ segments = [str(tgt_seq)] + [''.join(str(frg.seq) for frg in frgs) for _, frgs in others]
138
+
139
+ def row(index, seq):
140
+ """ seq in segment index, gaps in every other segment """
141
+ return Seq('/'.join(str(seq) if i == index else '-' * len(segment)
142
+ for i, segment in enumerate(segments)))
143
+
144
+ for templ in templs:
145
+ templ.seq = row(0, templ.seq)
146
+ for index, (ch_id, frgs) in enumerate(others, 1):
147
+ templs.append(_template(row(index, segments[index]), f'env{ch_id}',
148
+ self.templ_file, ch_id, frgs))
149
+ knowns.append(f'env{ch_id}')
150
+ tgt_seq = Seq('/'.join(segments))
151
+
152
+ _write_align(tgt_seq, templs, alin_file)
153
+
154
+ return self._automodel_run(alin_file, knowns, gaps if fix_known else None)
155
+
156
+ def _automodel_run(self, alin_file, knowns, gaps=None):
157
+ model_class = AutoModel if gaps is None else _gap_model_class(gaps)
158
+ amdl = model_class(
159
+ self.env,
160
+ alnfile=alin_file,
161
+ knowns=knowns,
162
+ sequence='target',
163
+ assess_methods=(assess.DOPE, assess.GA341)
164
+ )
165
+ amdl.starting_model = 1
166
+ amdl.ending_model = 1
167
+
168
+ # amdl.loop.starting_model = 1
169
+ # amdl.loop.ending_model = 1
170
+
171
+ orig_dir = os.getcwd()
172
+ os.chdir(self.tmpdir)
173
+ amdl.make()
174
+ os.chdir(orig_dir)
175
+
176
+ return amdl.outputs[0]
177
+
178
+ def __del__(self):
179
+ if not DEBUG:
180
+ shutil.rmtree(self.tmpdir)
181
+ else:
182
+ print(f"Using temporary folder: {self.tmpdir}")
183
+
184
+
185
+ def _place_fragments(frgs, length, offset):
186
+ """ Place the fragments in their canonical position, filling the gaps with '-'
187
+
188
+ Args:
189
+ frgs: fragments of the chain, their features[2] hold the canonical position
190
+ length (int): length of the target sequence
191
+ offset (int): residues trimmed from the start of the canonical sequence
192
+ """
193
+ placed = ['-'] * length
194
+ for frg in frgs:
195
+ first = int(frg.features[2].location.start) - 1 - offset
196
+ seq = str(frg.seq)
197
+ if first < 0 or first + len(seq) > length or \
198
+ set(placed[first:first + len(seq)]) != {'-'}:
199
+ return None
200
+ placed[first:first + len(seq)] = seq
201
+ return ''.join(placed)
202
+
203
+
204
+ # Refining only part of the model: https://salilab.org/modeller/10.8/manual/node23.html
205
+ def _gap_model_class(gaps):
206
+ """ AutoModel optimizing only the residues of the gaps, so the rest of the
207
+ model keeps the coordinates of the template """
208
+ class _GapAutoModel(AutoModel):
209
+ def select_atoms(self):
210
+ return Selection(*[self.residues[first - 1:last] for first, last in gaps])
211
+ return _GapAutoModel
212
+
213
+
214
+ def _template(seq, name, templ_file, ch_id, frgs):
215
+ """ Template record of the chain ch_id of templ_file, its fragments frgs """
216
+ return SeqRecord(
217
+ seq,
218
+ name,
219
+ "",
220
+ f"structureX:{templ_file}:"
221
+ f"{frgs[0].features[0].location.start}:"
222
+ f"{ch_id}:{frgs[-1].features[0].location.end}:"
223
+ f"{ch_id}:::-1.00: -1.00",
224
+ annotations={'molecule_type': 'protein'} # required for writing PIR aligment
225
+ )
226
+
227
+
228
+ def _write_align(tgt_seq, templs, alin_file):
229
+ SeqIO.write(
230
+ [
231
+ SeqRecord(
232
+ tgt_seq,
233
+ 'target',
234
+ '',
235
+ 'sequence:target:::::::0.00: 0.00',
236
+ annotations={'molecule_type': 'protein'}
237
+ )
238
+ ] + templs,
239
+ alin_file,
240
+ 'pir'
241
+ )
242
+
243
+
244
+ class NoCanSeqError(Exception):
245
+ """
246
+ | modeller_manager NoCanSeqError
247
+ | Error raised when no canonical sequence exists
248
+ """
249
+ def __init__(self, mod_id, ch_id):
250
+ self.message = f"No canonical sequence found for chain {ch_id}/{mod_id}"
@@ -1,5 +1,6 @@
1
1
  """ Module to manage sequence information for structures """
2
2
 
3
+ from shlex import split
3
4
  import sys
4
5
  import os
5
6
  import gzip
@@ -582,35 +583,33 @@ class SequenceData():
582
583
  strucm (StructureManager) : Object containing the loaded structure
583
584
  """
584
585
  summary = {}
585
- for mod in strucm.st:
586
- for ch_id in self.data[mod.id]:
587
- mismatches = []
588
- can_seq_mis = ''
589
- pdb_seq_mis = ''
590
-
591
- if not self.has_canonical[mod.id][ch_id]:
586
+ can_ids = [seq.split("\n")[0].split(' ')[0].replace('can_sq_', '') for seq in self.get_canonical().split('>')[1:] if seq]
587
+ can_seqs = [seq.split("\n")[1] for seq in self.get_canonical().split('>')[1:] if seq]
588
+ pdb_seqs = [seq.split("\n")[1] for seq in self.get_pdbseq().split('>')[1:] if seq]
589
+ i_chain = 0
590
+ for can_seq, pdb_seq in zip(can_seqs, pdb_seqs):
591
+ mismatches = []
592
+ can_seq_mis = ''
593
+ pdb_seq_mis = ''
594
+
595
+ for i in range(len(can_seq)):
596
+ if can_seq[i] != pdb_seq[i] and pdb_seq[i] != '-':
597
+ mismatches.append(i)
598
+ can_seq_mis += can_seq[i]
599
+ pdb_seq_mis += pdb_seq[i]
592
600
  continue
593
-
594
- can_seq = self.get_canonical().split("\n")[1]
595
- pdb_seq = self.get_pdbseq().split("\n")[1]
596
-
597
- for i in range(len(can_seq)):
598
- if can_seq[i] != pdb_seq[i] and pdb_seq[i] != '-':
599
- mismatches.append(i)
600
- can_seq_mis += can_seq[i]
601
- pdb_seq_mis += pdb_seq[i]
602
- continue
603
- can_seq_mis += '-'
604
- pdb_seq_mis += '-'
605
-
606
- if mismatches:
607
- summary[f"{ch_id}/{mod.id}"] = {
608
- 'mismatches': mismatches,
609
- 'canonical': can_seq_mis,
610
- 'structure': pdb_seq_mis
611
- }
601
+ can_seq_mis += '-'
602
+ pdb_seq_mis += '-'
603
+
604
+ if mismatches:
605
+ summary[can_ids[i_chain]]= {
606
+ 'mismatches': mismatches,
607
+ 'canonical': can_seq_mis,
608
+ 'structure': pdb_seq_mis
609
+ }
610
+ i_chain += 1
612
611
  return summary
613
-
612
+
614
613
  def _get_pack_str_seqs(strucm):
615
614
  strucm.revert_can_resnames(canonical=True)
616
615
  seqs = {}
@@ -159,9 +159,12 @@ def fetch_residue_name_by_id(res_id):
159
159
  ''' Fetch residue name from monomers API, with caching '''
160
160
  if res_id in MONOMER_NAME_CACHE:
161
161
  return MONOMER_NAME_CACHE[res_id]
162
- with urllib.request.urlopen(f"{MONOMERS_API_PREFIX}{res_id}/entry", timeout=10) as response:
163
- residue_data = json.load(response)
164
- name = residue_data.get('name', '').replace(res_id, '', 1).strip()
162
+ try:
163
+ with urllib.request.urlopen(f"{MONOMERS_API_PREFIX}{res_id}/entry", timeout=10) as response:
164
+ residue_data = json.load(response)
165
+ name = residue_data.get('name', '').replace(res_id, '', 1).strip()
166
+ except (urllib.error.URLError, json.JSONDecodeError):
167
+ name = ''
165
168
  MONOMER_NAME_CACHE[res_id] = name
166
169
  return name
167
170
 
@@ -756,7 +756,8 @@ class StructureChecking():
756
756
  * **residue_list** - Indicated terminals
757
757
  * **breaks** - Add caps to backbone breaks
758
758
  * **terms** - Add caps to true terminals
759
- * extra_gap (int) - ('0') Recover addiciontal residues from the model to improve match (experimental)
759
+ * extra_gap (int) - ('0') Recover additional residues from the model to improve match (experimental)
760
+ * fix_known (bool) - (False) Optimize only the missing residues, the ones in the structure keep their coordinates
760
761
  * no_recheck (bool) - (False) Do not recheck backbone after fixing
761
762
  * no_check_clashes (bool) - (False) Do not check for generated clashes
762
763
  """