keitaroyam / servalcat

Structure refinement and validation for crystallography and single particle analysis
Mozilla Public License 2.0
24 stars 3 forks source link

Show error when refmac5 command fails #13

Closed colinpalmer closed 1 year ago

colinpalmer commented 1 year ago

We've been seeing a problem trying to run Servalcat from some CCP-EM tools, for example:

# servalcat refine_spa --model /home/lbq76021/ccpem-project/LocScale/job009/processing_files/5ni1_uniform_biso.cif --resolution 2.2 --ncycle 10 --output_prefix 5ni1_servalcat_refined --map /home/lbq76021/ccpem-project/LocScale/job009/processing_files/emd_3488.mrc --jellybody --jellybody_params 0.01 4.2 --hydrogen no --keywords 'refi bonly'
Traceback (most recent call last):
  File "/dls_sw/apps/ccp4/8.0.015/ccp4-8.0/bin/servalcat", line 33, in <module>
    sys.exit(load_entry_point('servalcat==0.4.32', 'console_scripts', 'servalcat')())
  File "/dls_sw/apps/ccp4/8.0.015/ccp4-8.0/lib/python3.7/site-packages/servalcat/command_line.py", line 109, in main
    modules[args.command].main(args)
  File "/dls_sw/apps/ccp4/8.0.015/ccp4-8.0/lib/python3.7/site-packages/servalcat/spa/run_refmac.py", line 727, in main
    raise SystemExit("Error: Check Refmac instllation or use --exe to give the location.\n{}".format(e))
UnboundLocalError: local variable 'e' referenced before assignment

I see that you've already fixed the UnboundLocalError but the underlying problem is still occurring, i.e. it's failing to determine the refmac version and raising an error.

In my case I've traced it to a bad CCP4 environment setup - somehow my CCP4 environment variables are getting unset, so the refmac5 command can still be found but it fails with an error:

$ refmac5
>>>>>> CCP4 library signal ccp4_general:Cannot open environ.def (Error)
     raised in ccp4fyp <<<<<<
 refmac5:  Cannot open environ.def
 refmac5:  Cannot open environ.def
Times: User:       0.0s System:    0.0s Elapsed:     0:00  

Obviously this is not really Servalcat's problem! But it would be helpful to try to identify this kind of error and give the user an indication of what the problem might be. For example, maybe the check_version() function in servalcat/utils/refmac.py could check if ver == () before returning, and if so, print the refmac stdout and stderr to the log? Or even better if it could identify this specific problem and warn the user that their CCP4 environment is not set up properly.

keitaroyam commented 1 year ago

Thanks for reporting this. Servalcat 0.4.38 prints the raw output when it fails to check the version. I would appreciate it if you could do some tests.

colinpalmer commented 1 year ago

This seems to work nicely. Thanks for fixing it so quickly!