IMP logo
IMP Reference Guide  develop.50fdd7fa33,2025/09/05
The Integrative Modeling Platform
emseqfinder/mldb/tools.py
1 import os
2 
3 
4 def get_sequence_from_pdb(pdb):
5  '''
6  from a standard pdb file, return all RESNAME entries
7  from the Calpha atoms
8  '''
9  resnames = []
10  f = open(pdb)
11  for line in f.readlines():
12  if line[13:15] == "CA":
13  resnames.append(line[17:20])
14 
15  f.close()
16  return resnames
17 
18 
19 def is_poly_ala(pdb):
20  # Returns true if all residues are alanine
21  resis = get_sequence_from_pdb(pdb)
22  if all(r == 'ALA' for r in resis):
23  return True
24  else:
25  return False
26 
27 
28 def is_length_correct(pdb):
29  # returns
30  # pdb :
31  lenseq = int(os.path.basename(pdb).split("_")[-2])
32  resis = get_sequence_from_pdb(pdb)
33  if len(resis) == lenseq:
34  return True
35  else:
36  return False
37 
38 
39 def is_length_correct_for_parts(pdb):
40  # returns
41  # pdb :
42  resis = get_sequence_from_pdb(pdb)
43  if len(resis) > 2:
44  return True
45  else:
46  return False
47 
48 
49 def get_adjacent_values(em, voxel):
50  # returns a list of the value of all voxels
51  # plus one
52  import IMP.algebra
53  loc = em.get_location_by_voxel(voxel)
54  values = []
55  vecs = [(0, 0, 1), (0, 1, 0), (1, 0, 0),
56  (0, 0, -1), (0, -1, 0), (-1, 0, 0)]
57 
58  disps = [IMP.algebra.Vector3D(v) for v in vecs]
59 
60  for d in disps:
61  try:
62  values.append(em.get_value(loc+d))
63  except: # noqa: E722
64  pass
65 
66  return values
67 
68 
69 def get_voxel_position_string(dmap):
70  vstring = ''
71  for v in range(dmap.get_number_of_voxels()):
72  vstring += str(dmap.get_location_by_voxel(v))+" "
73  return vstring[0:-1]
74 
75 
76 def get_voxel_value_string(dmap, const=1):
77  vstring = ""
78  for v in range(dmap.get_number_of_voxels()):
79  vstring += str(round(dmap.get_value(v), 4))+" "
80  return vstring[0:-1]
81 
82 
83 def get_xml_line(xml, field):
84  f = open(xml, "r")
85 
86  for line in f.readlines():
87  if field in line:
88  f.close()
89  return line
90  f.close()
91  return None
92 
93 
94 def get_pdbid_from_xml(xml):
95  line = get_xml_line(xml, "<fittedPDBEntryId>")
96  if line is None:
97  return line
98  return line.strip().split("<fittedPDBEntryId>")[-1][0:4]
99 
100 
101 def get_threshold_from_xml(xml):
102  line = get_xml_line(xml, "contourLevel")
103  if line is None:
104  return line
105  return float(line.strip().split(">")[1].split("<")[0])
106 
107 
108 def get_resolution(emdb):
109  # get resolution information from EMDB
110  from config import get_xml
111  return get_resolution_from_xml(get_xml(emdb))
112 
113 
114 def get_resolution_from_xml(xml):
115  line = get_xml_line(xml, "<resolutionByAuthor>")
116  if line is None:
117  return line
118  return float(line.strip().split("<resolutionByAuthor>")[-1].split("<")[0])
119 
120 
121 def get_spacing_from_xml(xml):
122  line = get_xml_line(xml, "pixelX")
123  return float(line.strip().split(">")[1].split("<")[0])
124 
125 
126 def get_statistics_from_xml(xml):
127  # Returns voxel minimum, maximum, average and SD as a tuple
128  line = get_xml_line(xml, "<minimum>")
129  minimum = float(line.strip().split(">")[1].split("<")[0])
130  line = get_xml_line(xml, "<maximum>")
131  maximum = float(line.strip().split(">")[1].split("<")[0])
132  line = get_xml_line(xml, "<average>")
133  average = float(line.strip().split(">")[1].split("<")[0])
134  line = get_xml_line(xml, "<std>")
135  std = float(line.strip().split(">")[1].split("<")[0])
136  return (minimum, maximum, average, std)
137 
138 
139 def catstring(stuff, delimiter=" "):
140  outstring = ""
141  for s in stuff:
142  outstring += str(s)+delimiter
143 
144  return outstring[0:-1]
145 
146 
147 def tint(value, n=2):
148  return int(value*10**n)/10**n
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition: VectorD.h:408
double get_resolution(Model *m, ParticleIndex pi)
Estimate the resolution of the hierarchy as used by Representation.