| Home | Trees | Indices | Help |
|
|---|
|
|
1 ############################################################################# 2 # 3 # Author: Michel F. SANNER, Sophie COON 4 # 5 # Copyright: M. Sanner TSRI 2000 6 # 7 ############################################################################# 8 9 # 10 #$Header: /opt/cvs/python/packages/share1.5/MolKit/__init__.py,v 1.20.2.1 2007/08/10 11:47:26 annao Exp $ 11 # 12 #$Id: __init__.py,v 1.20.2.1 2007/08/10 11:47:26 annao Exp $ 13 # 14 15 import string 16 import os 17 1820 if not os.path.exists(filename): 21 raise AssertionError , "%s does't exist" %filename 22 from MolKit.pdbParser import PdbParser, PdbqParser,PdbqsParser,\ 23 PdbqtParser, PQRParser 24 from MolKit.mol2Parser import Mol2Parser 25 from MolKit.mmcifParser import MMCIFParser 26 ext = string.split(filename, '.') 27 if ext[-1]=='pdb': 28 parser = PdbParser(filename) 29 30 elif ext[-1]=='pdbq': 31 parser = PdbqParser(filename) 32 33 elif ext[-1]=='pdbqt': 34 parser = PdbqtParser(filename) 35 36 elif ext[-1]=='pdbqs': 37 parser = PdbqsParser(filename) 38 39 elif ext[-1]=='pqr': 40 parser = PQRParser(filename) 41 42 elif ext[-1]=='mol2': 43 parser = Mol2Parser(filename) 44 45 elif ext[-1]=='cif': 46 parser = MMCIFParser(filename) 47 48 else: 49 print "File Format unknown can't parse it" 50 return [] 51 molecules = parser.parse() 52 return molecules53 58 59 60 ## def getNodesByMolecule(self, nodes, molecules,nodeType=None): 61 ## """ moleculeSet, [nodeSet, nodeSet] <- getNodesByMolecule(nodes) 62 ## nodes can be either: a string, a TreeNode or a TreeNodeSet. 63 ## This method returns a molecule set and for each molecule a TreeNodeSet 64 ## of the nodes belonging to this molecule. 65 ## 'nodeType' enables a desired type of nodes to be returned for each 66 ## molecule 67 ## """ 68 69 ## # if it is a string, get a bunch of nodes from the string 70 ## if type(nodes)==types.StringType: 71 ## nodes = molecules.NodesFromName(nodes) 72 73 ## assert issubclass(nodes.__class__, TreeNode) or \ 74 ## issubclass(nodes.__class__, TreeNodeSet) 75 76 ## # if nodes is a single TreeNode make it a singleton TreeNodeSet 77 ## if issubclass(nodes.__class__, TreeNode): 78 ## nodes = nodes.setClass([nodes]) 79 80 ## if len(nodes)==0: return MoleculeSet([]), [] 81 82 ## # catch the case when nodes is already a MoleculeSet 83 ## if nodes.elementType in [Molecule, Protein]: 84 ## molecules = nodes 85 ## else: # get the set of molecules 86 ## molecules = nodes.top.uniq() 87 88 ## # build the set of nodes for each molecule 89 ## nodeSets = [] 90 91 ## # find out the type of the nodes we want to return 92 ## searchType=0 93 ## if nodeType is None: 94 ## Klass = nodes.elementType # class of objects in that set 95 ## else: 96 ## assert issubclass(nodeType, TreeNode) 97 ## Klass = nodeType 98 ## if Klass != nodes.elementType: 99 ## searchType=1 100 101 ## for mol in molecules: 102 ## # get set of nodes for this molecule 103 ## mol_nodes = nodes.get(lambda x, mol=mol: x.top==mol) 104 105 ## # get the required types of nodes 106 ## if searchType: 107 ## if Klass == Atom and hasattr(mol_nodes, 'allAtoms'): 108 ## mol_nodes = mol_nodes.allAtoms 109 ## else: 110 ## mol_nodes = mol_nodes.findType( Klass ) 111 112 ## nodeSets.append( mol_nodes ) 113 114 ## return molecules, nodeSets 115 116 ## from MolKit.protein import ProteinSet, Protein,ResidueSet, Residue, ChainSet, Chain 117 ## from MolKit.molecule import AtomSet, Atom, MoleculeSet, Molecule 118 119 ## def getNodesByLevel(self, nodes, molecules,levelType=Protein, nodeType=None): 120 ## """ ProteinSet, [nodeSet, nodeSet] <- getNodesByLevel(nodes) 121 ## nodes can be either: a string, a TreeNode or a TreeNodeSet. 122 ## This method returns a molecullevel set and for each level a TreeNodeSet 123 ## of the nodes belonging to this molecule. 124 ## 'nodeType' enables a desired type of nodes to be returned for each 125 ## molecule 126 ## """ 127 ## import types 128 ## # if it is a string, get a bunch of nodes from the string 129 ## if type(nodes)==types.StringType: 130 ## nodes = molecules.NodesFromName(nodes) 131 132 ## assert issubclass(nodes.__class__, TreeNode) or \ 133 ## issubclass(nodes.__class__, TreeNodeSet) 134 135 ## # if nodes is a single TreeNode make it a singleton TreeNodeSet 136 ## if issubclass(nodes.__class__, TreeNode): 137 ## nodes = nodes.setClass([nodes]) 138 139 ## if len(nodes)==0: 140 ## levelSet = str(levelType)+'Set([])' 141 ## return eval(levelSet), [] 142 143 ## # catch the case when nodes is already a MoleculeSet 144 ## if nodes.elementType == levelType: 145 ## levelSets = nodes 146 ## else: # get the set of molecules 147 ## levelSets = nodes.findType(levelType).uniq() 148 149 ## # build the set of nodes for each molecule 150 ## nodeSets = [] 151 152 ## # find out the type of the nodes we want to return 153 ## searchType=0 154 ## if nodeType is None: 155 ## Klass = nodes.elementType # class of objects in that set 156 ## else: 157 ## assert issubclass(nodeType, TreeNode) 158 ## Klass = nodeType 159 ## if Klass != nodes.elementType: 160 ## searchType=1 161 162 ## for level in levelSets: 163 ## # get set of nodes for this molecule 164 ## mol_nodes = nodes.get(lambda x, mol=mol: x.top==mol) 165 ## #level_nodes = nodes.get(lambda x, 166 ## #nodes.get(lambda x, levelType = levelType, level = level: x.findType(levelType) # get the required types of nodes 167 ## if searchType: 168 ## if Klass == Atom and hasattr(mol_nodes, 'allAtoms'): 169 ## mol_nodes = mol_nodes.allAtoms 170 ## else: 171 ## mol_nodes = mol_nodes.findType( Klass ) 172 173 ## nodeSets.append( mol_nodes ) 174 175 ## return molecules, nodeSets 176 177 CRITICAL_DEPENDENCIES = ['mglutil', 'Numeric'] 178 NONCRITICAL_DEPENDENCIES =['sff', 'PyBabel', 'stride', 'bhtree', 'NetworkEditor', 'DejaVu', 'mslib', 'Vision','Pmv', 'cMolKit', 'symserv', '_xmlplus'] 179
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0alpha3 on Fri Nov 2 14:12:27 2007 | http://epydoc.sourceforge.net |