19 import os, tempfile, ftplib, httplib
22 from ost
import mol, geom, conop, seq
31 return IOProfileRegistry.Instance().Get(key)
34 if isinstance(value, str):
35 value=self[value].Copy()
36 IOProfileRegistry.Instance().Set(key, value)
40 return len(self.
_dict)
43 return self._dict.__iter__()
47 if conop.GetDefaultLib():
51 profiles[
'STRICT']=
IOProfile(dialect=
'PDB', fault_tolerant=
False,
52 quack_mode=
False, processor=processor.Copy())
53 profiles[
'SLOPPY']=
IOProfile(dialect=
'PDB', fault_tolerant=
True,
54 quack_mode=
True, processor=processor.Copy())
55 profiles[
'CHARMM']=
IOProfile(dialect=
'CHARMM', fault_tolerant=
True,
56 quack_mode=
False, processor=processor.Copy())
57 profiles[
'DEFAULT']=
'STRICT'
59 def _override(val1, val2):
65 def LoadPDB(filename, restrict_chains="", no_hetatms=None,
66 fault_tolerant=
None, load_multi=
False, quack_mode=
None,
67 join_spread_atom_records=
None, calpha_only=
None,
68 profile=
'DEFAULT', remote=
False, dialect=
None,
69 seqres=
False, bond_feasibility_check=
None):
71 Load PDB file from disk and return one or more entities. Several options
72 allow to customize the exact behaviour of the PDB import. For more information
73 on these options, see :doc:`profile`.
75 Residues are flagged as ligand if they are mentioned in a HET record.
77 :param restrict_chains: If not an empty string, only chains listed in the
78 string will be imported.
80 :param fault_tolerant: Enable/disable fault-tolerant import. If set, overrides
81 the value of :attr:`IOProfile.fault_tolerant`.
83 :param no_hetatms: If set to True, HETATM records will be ignored. Overrides
84 the value of :attr:`IOProfile.no_hetatms`
86 :param load_multi: If set to True, a list of entities will be returned instead
87 of only the first. This is useful when dealing with multi-PDB files.
89 :param join_spread_atom_records: If set, overrides the value of
90 :attr:`IOProfile.join_spread_atom_records`.
92 :param remote: If set to True, the method tries to load the pdb from the
93 remote pdb repository www.pdb.org. The filename is then interpreted as the
96 :rtype: :class:`~ost.mol.EntityHandle` or a list thereof if `load_multi` is
99 :param dialect: Specifies the particular dialect to use. If set, overrides
100 the value of :attr:`IOProfile.dialect`
102 :param seqres: Whether to read SEQRES records. If set to True, the loaded
103 entity and seqres entry will be returned as a tuple.
105 :type dialect: :class:`str`
108 :raises: :exc:`~ost.io.IOException` if the import fails due to an erroneous or
111 def _override(val1, val2):
116 if isinstance(profile, str):
117 prof=profiles[profile].Copy()
118 elif isinstance(profile, IOProfile):
121 raise TypeError(
'profile must be of type string or IOProfile, '+\
122 'instead of %s'%type(profile))
123 if dialect
not in (
None,
'PDB',
'CHARMM',):
124 raise ValueError(
'dialect must be PDB or CHARMM')
125 prof.calpha_only=_override(prof.calpha_only, calpha_only)
126 prof.no_hetatms=_override(prof.no_hetatms, no_hetatms)
127 prof.dialect=_override(prof.dialect, dialect)
128 prof.quack_mode=_override(prof.quack_mode, quack_mode)
130 prof.processor.check_bond_feasibility=_override(prof.processor.check_bond_feasibility,
131 bond_feasibility_check)
132 prof.fault_tolerant=_override(prof.fault_tolerant, fault_tolerant)
133 prof.join_spread_atom_records=_override(prof.join_spread_atom_records,
134 join_spread_atom_records)
140 filename = tmp_file.name
142 conop_inst=conop.Conopology.Instance()
144 if prof.dialect==
'PDB':
145 prof.processor.dialect=conop.PDB_DIALECT
146 elif prof.dialect==
'CHARMM':
147 prof.processor.dialect=conop.CHARMM_DIALECT
149 reader.read_seqres=seqres
153 while reader.HasNext():
154 ent=mol.CreateEntity()
155 reader.Import(ent, restrict_chains)
157 prof.processor.Process(ent)
160 raise IOError(
"File '%s' doesn't contain any entities" % filename)
163 ent=mol.CreateEntity()
165 reader.Import(ent, restrict_chains)
167 prof.processor.Process(ent)
169 raise IOError(
"File '%s' doesn't contain any entities" % filename)
171 return ent, reader.seqres
176 def SavePDB(models, filename, dialect=None, pqr=False, profile='DEFAULT'):
178 Save entity or list of entities to disk. If a list of entities is supplied
179 the PDB file will be saved as a multi PDB file. Each of the entities is
180 wrapped into a MODEL/ENDMDL pair.
182 If the atom number exceeds 99999, '*****' is used.
184 :param models: The entity or list of entities (handles or views) to be saved
185 :param filename: The filename
186 :type filename: string
188 if not getattr(models,
'__len__',
None):
190 if isinstance(profile, str):
191 profile=profiles[profile].Copy()
192 elif isinstance(profile, IOProfile):
195 raise TypeError(
'profile must be of type string or IOProfile, '+\
196 'instead of %s'%type(profile))
197 profile.dialect=_override(profile.dialect, dialect)
201 writer.write_multi_model=
True
218 image_list.append(image)
221 LoadMapList=LoadImageList
224 lazy_load=
False, stride=1,
225 dialect=
None, detect_swap=
True,swap_bytes=
False):
227 Load CHARMM trajectory file.
229 :param crd: EntityHandle or filename of the (PDB) file containing the
230 structure. The structure must have the same number of atoms as the
232 :param dcd_file: The filename of the DCD file. If not set, and crd is a
233 string, the filename is set to the <crd>.dcd
234 :param layz_load: Whether the trajectory should be loaded on demand. Instead
235 of loading the complete trajectory into memory, the trajectory frames are
236 loaded from disk when requested.
237 :param stride: The spacing of the frames to load. When set to 2, for example,
238 every second frame is loaded from the trajectory. By default, every frame
240 :param dialect: The dialect for the PDB file to use. See :func:`LoadPDB`. If
241 set, overrides the value of the profile
242 :param profile: The IO profile to use for loading the PDB file. See
244 :param detect_swap: if True (the default), then automatic detection of endianess
245 is attempted, otherwise the swap_bytes parameter is used
246 :param swap_bytes: is detect_swap is False, this flag determines whether bytes
247 are swapped upon loading or not
251 dcd_file=
'%s.dcd' % os.path.splitext(crd)[0]
252 crd=
LoadPDB(crd, profile=profile, dialect=dialect)
256 raise ValueError(
"No DCD filename given")
257 return LoadCHARMMTraj_(crd, dcd_file, stride, lazy_load, detect_swap, swap_bytes)
259 def LoadMMCIF(filename, fault_tolerant=None, calpha_only=None, profile='DEFAULT', remote=False, seqres=False, info=False):
261 Load MMCIF file from disk and return one or more entities. Several options
262 allow to customize the exact behaviour of the MMCIF import. For more
263 information on these options, see :doc:`profile`.
265 Residues are flagged as ligand if they are mentioned in a HET record.
267 :param fault_tolerant: Enable/disable fault-tolerant import. If set, overrides
268 the value of :attr:`IOProfile.fault_tolerant`.
270 :param remote: If set to True, the method tries to load the pdb from the
271 remote pdb repository www.pdb.org. The filename is then interpreted as the
274 :rtype: :class:`~ost.mol.EntityHandle`.
276 :param seqres: Whether to read SEQRES records. If set to True, the loaded
277 entity and seqres entry will be returned as second item.
279 :param info: Whether to return an info container with the other output.
280 Returns a :class:`MMCifInfo` object as last item.
282 :raises: :exc:`~ost.io.IOException` if the import fails due to an erroneous
283 or non-existent file.
285 def _override(val1, val2):
290 if isinstance(profile, str):
291 prof = profiles[profile].Copy()
293 prof = profile.Copy()
295 prof.calpha_only=_override(prof.calpha_only, calpha_only)
296 prof.fault_tolerant=_override(prof.fault_tolerant, fault_tolerant)
300 tmp_file =
RemoteGet(filename, from_repo=
'cif')
301 filename = tmp_file.name
304 ent = mol.CreateEntity()
306 reader.read_seqres = seqres
315 prof.processor.Process(ent)
319 return ent, reader.seqres, reader.info
321 return ent, reader.seqres
323 return ent, reader.info
334 def _PDBize(biounit, asu, seqres=None, min_polymer_size=10,
335 transformation=
False):
338 chains = biounit.GetChainList()
339 c_intvls = biounit.GetChainIntervalList()
340 o_intvls = biounit.GetOperationsIntervalList()
343 ss = seq.CreateSequenceList()
348 operations = biounit.GetOperations()
349 for i
in range(0,len(c_intvls)):
351 l_operations = operations[o_intvls[i][0]:o_intvls[i][1]]
352 if len(l_operations) > 0:
353 for op
in l_operations[0]:
355 rot.PasteRotation(op.rotation)
357 trans.PasteTranslation(op.translation)
360 trans_matrices.append(tr)
361 for op_n
in range(1, len(l_operations)):
363 for o
in l_operations[op_n]:
365 rot.PasteRotation(o.rotation)
367 trans.PasteTranslation(o.translation)
370 for t_o
in trans_matrices:
373 trans_matrices = tmp_ops
375 assu = asu.Select(
'cname='+
','.join(chains[c_intvls[i][0]:c_intvls[i][1]]))
376 pdbizer.Add(assu, trans_matrices, ss)
377 pdb_bu = pdbizer.Finish(transformation)
379 return pdb_bu, pdb_bu.GetTransformationMatrix()
382 MMCifInfoBioUnit.PDBize = _PDBize
DLLEXPORT_OST_IO img::ImageHandle LoadImage(const boost::filesystem::path &loc)
Function that loads an image from a file.
std::vector< Mat4 > Mat4List
mol::CoordGroupHandle DLLEXPORT_OST_IO LoadCHARMMTraj(const mol::EntityHandle &ent, const String &trj_filename, unsigned int stride=1, bool lazy_load=false, bool detect_swap=true, bool byte_swap=false)
import a CHARMM trajectory in dcd format with an existing entity requires the existing entity and the...
reader for the mmcif file format
Manages a collection of images.