Skip to content

Instantly share code, notes, and snippets.

@samberg
Created November 21, 2014 03:13
Show Gist options
  • Select an option

  • Save samberg/68cc8f1bc92f03bdd2aa to your computer and use it in GitHub Desktop.

Select an option

Save samberg/68cc8f1bc92f03bdd2aa to your computer and use it in GitHub Desktop.
def read_molecule(reader):
line=reader.readline()
if not line:
return None
while not line.startswith('COMPND'):
line=reader.readline()
key, name = line.split()
molecule=[name]
line = reader.readline()
while not line.startswith('END'):
key, num, atom_type, x, y, z = line.split()
molecule.append([atom_type, x, y, z])
line = reader.readline()
return molecule
def read_all_molecules(reader):
result = []
reading=True
while reading:
molecule = read_molecule(reader)
if molecule:
result.append(molecule)
else:
reading=False
return result
if __name__ == '__main__':
molecule_file = open('PDB.txt', 'r')
molecules = read_all_molecules(molecule_file)
print(molecules)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment