Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def read_molecule(reader):
  2. line=reader.readline()
  3. if not line:
  4. return None
  5. while not line.startswith('COMPND'):
  6. line=reader.readline()
  7.  
  8. key, name = line.split()
  9. molecule=[name]
  10. line = reader.readline()
  11. while not line.startswith('END'):
  12. key, num, atom_type, x, y, z = line.split()
  13. molecule.append([atom_type, x, y, z])
  14. line = reader.readline()
  15.  
  16.  
  17. return molecule
  18.  
  19. def read_all_molecules(reader):
  20. result = []
  21. reading=True
  22. while reading:
  23. molecule = read_molecule(reader)
  24. if molecule:
  25. result.append(molecule)
  26. else:
  27. reading=False
  28.  
  29. return result
  30.  
  31.  
  32.  
  33.  
  34.  
  35. if __name__ == '__main__':
  36. molecule_file = open('PDB.txt', 'r')
  37. molecules = read_all_molecules(molecule_file)
  38. print(molecules)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement