Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading a Gromacs topology fails when an insertion code exists #1153

Closed
Valdes-Tresanco-MS opened this issue Mar 2, 2021 · 1 comment
Closed
Labels

Comments

@Valdes-Tresanco-MS
Copy link
Contributor

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

@Valdes-Tresanco-MS
Copy link
Contributor Author

Fixed via #1219 and #1220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants