Skip to content

Commit

Permalink
Fix bug in atom names when molecules from SMILES
Browse files Browse the repository at this point in the history
  • Loading branch information
martimunicoy committed Aug 25, 2020
1 parent 351b170 commit d6a7af4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions offpele/utils/toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,19 @@ def to_pdb_file(self, molecule, path):
assert Path(path).suffix == '.pdb', 'Wrong extension'

rdkit_molecule = molecule.rdkit_molecule

pdb_block = Chem.rdmolfiles.MolToPDBBlock(rdkit_molecule)
names = molecule.get_pdb_atom_names()

renamed_pdb_block = ''
for line, name in zip(pdb_block.split('\n'), names):
renamed_pdb_block += line[:12] + name + line[16:] + '\n'

for line in pdb_block.split('\n')[len(names):]:
renamed_pdb_block += line + '\n'

with open(path, 'w') as f:
writer = Chem.PDBWriter(f)
writer.write(rdkit_molecule)
writer.close()
f.write(renamed_pdb_block)

def to_sdf_file(self, molecule, path):
"""
Expand Down

0 comments on commit d6a7af4

Please sign in to comment.