-
Notifications
You must be signed in to change notification settings - Fork 160
Closed
Labels
Description
Hi
First of all, parmed is awesome. Good work!
Recently, I have used parmed to read an antibody Gromacs topology. The topology contains insert codes and when reading it ends in an error.
ValueError: invalid literal for int () with base 10: '27A'
When the line that contains the information of each atom is processed, it is divided by spaces, so if the residue contains an insertion code then this error is obtained.
A possible solution would be:
change this method https://github.com/ParmEd/ParmEd/master/parmed/gromacs/gromacstop.py#L562-588
def _parse_atoms(self, line, params):
""" Parses an atom line. Returns an Atom, resname, resnum """
words = line.split()
try:
attype = params.atom_types[words[1]]
except KeyError:
attype = None
if len(words) < 8:
if attype is not None:
mass = attype.mass
atomic_number = attype.atomic_number
else:
mass = -1
atomic_number = -1
else:
mass = float(words[7])
if attype is not None and attype.atomic_number >= 0:
atomic_number = attype.atomic_number
else:
atomic_number = AtomicNum[element_by_mass(mass)]
charge = float(words[6]) if len(words) > 6 else None
if atomic_number == 0:
atom = ExtraPoint(name=words[4], type=words[1], charge=charge)
else:
atom = Atom(atomic_number=atomic_number, name=words[4],
type=words[1], charge=charge, mass=mass)
# fix this error
if words[2][-1] in letters:
icode = words[2][-1]
resnum = int(words[2][:-1])
else:
icode = ''
resnum = int(words[2])
return atom, words[3], resnum, icode
and modified this line https://github.com/ParmEd/ParmEd/master/parmed/gromacs/gromacstop.py#L407
elif current_section == 'atoms':
atom, resname, resnum, icode = self._parse_atoms(line, params)
molecule.add_atom(atom, resname, resnum, inscode=icode)
I do not do a PR because it can take time and it is simple. I hope this helps and can fix it.
Best regards
Mario