00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 from _io import *
00020 from ost import mol, conop
00021
00022 def LoadPDB(filename, restrict_chains="", no_hetatms=False,
00023 fault_tolerant=False, load_multi=False,
00024 join_spread_atom_records=False, calpha_only=False):
00025 """
00026 Load PDB file from disk and returns one or more entities. Several options
00027 allow to customize the exact behaviour of the PDB import.
00028
00029 :param restrict_chains: If not an empty string, only chains listed in the
00030 string will be imported.
00031
00032 :param fault_tolerant: If True, the import will succeed, even if the
00033 PDB contains faulty records. The faulty records will be ignored and import
00034 continues as if the records haven't been present.
00035
00036 :param no_hetatms: If set to True, HETATM records will be ignored
00037
00038 :param load_multi: If set to True, a list of entities will be returned instead
00039 of only the first. This is useful when dealing with multi-PDB files.
00040
00041 :param join_spread_atom_records: If set to true, atom records belonging to the
00042 same residue are joined, even if they do not appear sequentially in the PDB
00043 file.
00044 :rtype: :class:`~ost.mol.EntityHandle` or a list thereof if `load_multi` is
00045 True.
00046
00047 :raises: :exc:`~ost.io.IOException` if the import fails due to an erroneous or
00048 inexistent file
00049 """
00050 conop_inst=conop.Conopology.Instance()
00051 builder=conop_inst.GetBuilder("DEFAULT")
00052 reader=PDBReader(filename)
00053
00054 flags=0
00055 if calpha_only:
00056 flags|=PDB.CALPHA_ONLY
00057 if fault_tolerant:
00058 flags|=PDB.SKIP_FAULTY_RECORDS
00059 if no_hetatms:
00060 flags|=PDB.NO_HETATMS
00061 if join_spread_atom_records:
00062 flags|=PDB.JOIN_SPREAD_ATOM_RECORDS
00063 try:
00064 PDB.PushFlags(PDB.Flags() | flags)
00065 if load_multi:
00066 ent_list=[]
00067 while reader.HasNext():
00068 ent=mol.CreateEntity()
00069 reader.Import(ent, restrict_chains)
00070 conop_inst.ConnectAll(builder, ent, 0)
00071 ent_list.append(ent)
00072 PDB.PopFlags()
00073 return ent_list
00074 else:
00075 ent=mol.CreateEntity()
00076 if reader.HasNext():
00077 reader.Import(ent, restrict_chains)
00078 conop_inst.ConnectAll(builder, ent, 0)
00079 PDB.PopFlags()
00080 return ent
00081 except:
00082 PDB.PopFlags()
00083 raise
00084
00085 def SavePDB(models, filename):
00086 """
00087 Save entity or list of entities to disk. If a list of entities is supplied the
00088 PDB file will be saved as a multi PDB file. Each of the entities is wrapped
00089 into a MODEL/ENDMDL pair.
00090
00091 :param models: The entity or list of entities (handles or views) to be saved
00092 :param filename: The filename
00093 :type filename: string
00094 """
00095 if not getattr(models, '__len__', None):
00096 models=[models]
00097 writer=PDBWriter(filename)
00098 try:
00099 if len(models)>1:
00100 PDB.PushFlags(PDB.Flags() |PDB.WRITE_MULTIPLE_MODELS)
00101 else:
00102 PDB.PushFlags(0)
00103 for model in models:
00104 writer.Write(model)
00105 PDB.PopFlags()
00106 except:
00107 PDB.PopFlags()
00108 raise
00109 try:
00110 from ost import img
00111 LoadMap = LoadImage
00112 SaveMap = SaveImage
00113 except ImportError:
00114 pass
00115
00116
00117
00118 def LoadImageList (files):
00119 image_list=img.ImageList()
00120 for file in files:
00121 image=LoadImage(file)
00122 image_list.append(image)
00123 return image_list
00124
00125 LoadMapList=LoadImageList
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138