Pyem can't convert the .cs file to .star

Dear all,

I recently faced the issue about pyem csparc2star.py. I imported the Motion corrected micrographs in cryosparc V4.4.1 and generated a file.cs, and I also did CTF in relion 5. I used the command as follows:
csparc2star.py file.cs file.star --copy-micrograph-coordinates CtfFind/job003/raw --strip-uid
But it can’t work and the error is
Traceback (most recent call last):
File “…path/Soft/miniconda3/envs/pyem/lib/python3.11/site-packages/pandas/core/indexes/base.py”, line 3805, in get_loc
return self._engine.get_loc(casted_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “index.pyx”, line 167, in pandas._libs.index.IndexEngine.get_loc
File “index.pyx”, line 196, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘rlnImageName’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “…path/csparc2star.py”, line 181, in
sys.exit(main(parser.parse_args()))
^^^^^^^^^^^^^^^^^^^^^^^^^
File “…path/csparc2star.py”, line 107, in main
df = star.augment_star_ucsf(df, inplace=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “…path/Soft/pyem/pyem/star.py”, line 637, in augment_star_ucsf
if “@” in df.iloc[0][Relion.IMAGE_NAME]:
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File “…path/Soft/miniconda3/envs/pyem/lib/python3.11/site-packages/pandas/core/series.py”, line 1112, in getitem
return self._get_value(key)
^^^^^^^^^^^^^^^^^^^^
File “…path/Soft/miniconda3/envs/pyem/lib/python3.11/site-packages/pandas/core/series.py”, line 1228, in _get_value
loc = self.index.get_loc(label)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “…path/Soft/miniconda3/envs/pyem/lib/python3.11/site-packages/pandas/core/indexes/base.py”, line 3812, in get_loc
raise KeyError(key) from err
KeyError: ‘rlnImageName’

Could anyone help me with this issue? Thank you so much.

Best,

Feng

I’m getting a very similar error, which I’ve posted below. @DanielAsarnow Could you take a look into it when you get a chance?

csparc2star.py J22_002_particles.cs J22_002_particles.star --copy-micrograph-coordinates …/J1/part005.star
Traceback (most recent call last):
File “/programs/x86_64-linux/pyem/20231010/miniconda/envs/pyem/lib/python3.11/site-packages/pandas/core/indexes/base.py”, line 3790, in get_loc
return self._engine.get_loc(casted_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “index.pyx”, line 152, in pandas._libs.index.IndexEngine.get_loc
File “index.pyx”, line 181, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘rlnImageName’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/programs/x86_64-linux/pyem/20231010/pyem/csparc2star.py”, line 179, in
sys.exit(main(parser.parse_args()))
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/programs/x86_64-linux/pyem/20231010/pyem/csparc2star.py”, line 105, in main
df = star.augment_star_ucsf(df, inplace=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/lustre/fs4/ruit/scratch/sbgrid/programs/x86_64-linux/pyem/20231010/pyem/pyem/star.py”, line 637, in augment_star_ucsf
if “@” in df.iloc[0][Relion.IMAGE_NAME]:
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File “/programs/x86_64-linux/pyem/20231010/miniconda/envs/pyem/lib/python3.11/site-packages/pandas/core/series.py”, line 1040, in getitem
return self._get_value(key)
^^^^^^^^^^^^^^^^^^^^
File “/programs/x86_64-linux/pyem/20231010/miniconda/envs/pyem/lib/python3.11/site-packages/pandas/core/series.py”, line 1156, in _get_value
loc = self.index.get_loc(label)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/programs/x86_64-linux/pyem/20231010/miniconda/envs/pyem/lib/python3.11/site-packages/pandas/core/indexes/base.py”, line 3797, in get_loc
raise KeyError(key) from err
KeyError: ‘rlnImageName’

Hi
I found a way to solve it. You can reinstall the pyem by using zhengruan’s pyem (GitHub - zruan/pyem: Python programs for electron microscopy). He fixed the pandas str method issue.

Best,

Feng

Thanks so much! I’ll give it a shot

The error appears to be caused by you not including the passthrough file containing that information (the image names). The “fix” in that fork of pyem doesn’t really make sense. The UIDs are stripped before rlnImageName or the micrograph coordinates are used to try and match exported particles to the star file. Anyway, I don’t think those changes are relevant now.