-
Notifications
You must be signed in to change notification settings - Fork 772
Closed
Description
Expected behavior
I expect MDAnalysis to be able to parse standard MOL2 files.
Actual behavior
If I understand correctly the MOL2 standard, a <TRIPOS>ATOM data line only requires the 6 following fields: atom_id atom_name x y z atom_type. However, the MOL2Parser expects also the following optional fields to be present [subst_id [subst_name [charge [status_bit]]]] (actually, only the first three; see #2318).
Code to reproduce the behavior
from io import StringIO
import MDAnalysis as mda
print(mda.__version__)
mol2="""\
@<TRIPOS>MOLECULE
MOL2
2
SMALL
NO_CHARGES
@<TRIPOS>ATOM
1 N1 6.8420 9.9900 22.7430 N.am
2 N2 4.4000 9.1300 20.4710 N.am
"""
u = mda.Universe(StringIO(mol2), format='MOL2')2.0.0-dev0
Traceback (most recent call last):
File "/Users/rmeli/Documents/git/software/mdanalysis/package/MDAnalysis/core/universe.py", line 122, in _topology_from_file_like
topology = p.parse(**kwargs)
File "/Users/rmeli/Documents/git/software/mdanalysis/package/MDAnalysis/topology/MOL2Parser.py", line 153, in parse
aid, name, x, y, z, atom_type, resid, resname, charge = a.split()[:9]
ValueError: not enough values to unpack (expected 9, got 6)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test2.py", line 20, in <module>
u = mda.Universe(StringIO(mol2), format='MOL2')
File "/Users/rmeli/Documents/git/software/mdanalysis/package/MDAnalysis/core/universe.py", line 338, in __init__
**kwargs)
File "/Users/rmeli/Documents/git/software/mdanalysis/package/MDAnalysis/core/universe.py", line 140, in _topology_from_file_like
"Error: {2}".format(topology_file, parser, err))
ValueError: Failed to construct topology from file None with parser <class 'MDAnalysis.topology.MOL2Parser.MOL2Parser'>.
Error: not enough values to unpack (expected 9, got 6)
Current version of MDAnalysis
- Which version are you using?
2.0.0-dev0 - Which version of Python?
ython 3.7.10 - Which operating system?
macOS 11.5.1
Additional Information
This is linked to #2318 and my fix in #2319 was only partial. Other fields should be optional (especially important if NO_CHARGES in @<TRIPOS>MOLECULE is present).
The problematic line is the following:
| aid, name, x, y, z, atom_type, resid, resname, charge = a.split()[:9] |