Skip to content

Instantly share code, notes, and snippets.

@juanjosecas
Forked from samberg/pdb.py
Created December 6, 2016 20:56
Show Gist options
  • Select an option

  • Save juanjosecas/1ad54fa177a9cb8b8abff3cc95560176 to your computer and use it in GitHub Desktop.

Select an option

Save juanjosecas/1ad54fa177a9cb8b8abff3cc95560176 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