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

Bugfix and minor cleanup of ResultsSummary code + control SHELXE use depending on resolution #52

Merged
merged 5 commits into from
Jun 28, 2018

Conversation

linucks
Copy link
Contributor

@linucks linucks commented Jun 25, 2018

Needs refactoring but not today...

@linucks linucks changed the title Bugfix and minor cleanup of ResultsSummary code Bugfix and minor cleanup of ResultsSummary code + control SHELXE use depending on resolution Jun 25, 2018
Copy link
Contributor

@fsimkovic fsimkovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, think we should also consider either always raise-ing exceptions or calling ample_util.exit_util. Currently it's mixed in the code and I think that's very inconsistent.

My vote is for the former, since that enables others to use AMPLE more like a library with their own error handling rather than applications just exiting.

optd['tmscore_exe'] = 'TMscore' + ample_util.EXE_EXT
try:
optd['tmscore_exe'] = ample_util.find_exe(optd['tmscore_exe'])
optd['have_tmscore'] = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to a try - except - else ... we're not really testing the setting of a variable.

try:
    optd['tmscore_exe'] = ample_util.find_exe(optd['tmscore_exe'])
except ample_util.FileNotFoundError:
    logger.warning("Cannot find TMScore executable: %s", optd['tmscore_exe'])
    optd['maxcluster_exe'] = maxcluster.find_maxcluster(optd)
    optd['have_tmscore'] = False
else:
    optd['have_tmscore'] = True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the change of logger message from debug to warning, since the former is what we're really looking for.

# Modelling and ensemble options
#
###############################################################################
logger.info('Running on %d processors' % optd['nproc'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comma-separated instead of %

# cluster queueing
if optd['submit_qtype']:
optd['submit_qtype'] = optd['submit_qtype'].upper()
if optd['submit_cluster'] and not optd['submit_qtype']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not deprecate the -submit_cluster flag? Not necessarily remove it entirely but add a warning message to the help menu and make it do nothing ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but that's something for a separate pull request

if optd['purge']:
purge = optd['purge']
# Need to handle ackward compatibility where purge was boolean
if purge is True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can typecast the bool to int simply by putting int(True)

>>> int(True)
1
>>> int(False)
0

So this entire bit of code should probably be simply

try:
    opt['purge'] = int(opt['purge'])
except ValueError:
   msg = 'Purge must be specified as an integer, got: {}'.format(optd['purge'])
   exit_util.exit_error(msg)
logger.info('*** Purge mode level %d specified - intermediate files will be deleted ***', optd['purge'])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - I love getting rid of unneeded code!

@@ -381,6 +325,16 @@ def process_options(optd):
msg = "Cannot find theseus executable: {0}".format(optd['theseus_exe'])
exit_util.exit_error(msg)

# SCRWL - we always check for SCRWL as if we are processing QUARK models we want to add sidechains to them
if not optd['scwrl_exe']:
optd['scwrl_exe'] = 'Scwrl4' + ample_util.EXE_EXT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make absolute path to binary by setting os.path.join(os.environ['CCP4'], 'bin', 'Scwrl4' + ample_util.EXE_EXT)

if optd['phaser_rms'] != 'auto':
try:
phaser_rms = float(optd['phaser_rms'])
optd['phaser_rms'] = phaser_rms
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use again the try - except - else statement structure. Assignment is not really part of the try - except clause

#
if optd['use_shelxe']:
if optd['mtz_max_resolution'] > mrbump_util.SHELXE_MAX_PERMITTED_RESOLUTION:
logger.warn("Disabling use of SHELXE as max resolution of {} is < accepted limit of {}".\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ,-seperated handling instead of .format

logger.info('Making fragments (including homologues)')
# Model building programs
if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
if not (os.environ.has_key('warpbin')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAAAAAAAARRRRGH ... don't ever ever ever use has_key again!!

Only joking, it's deprecated in Python 3.X and not really recommended either. Turn this into 'warpbin' in os.environ.

logger.info('\nMaking Rosetta Models')
else:
logger.info('NOT making Rosetta Models')
logger.info('Using arpwarp script: {0}'.format(os.path.join(os.environ['warpbin'], "auto_tracing.sh")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ,-seperated handling instead of .format

self.assertFalse(options.d['use_shelxe'])
self.assertFalse(options.d['shelxe_rebuild'])

# Check we don't accidently turn it off if above limit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being picky I'd turn this into a separate test function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but no ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yes ;-)

Typecast to check for purge option
Change use of format to arguments for logger
Set path to $CCP4/bin for shipped executables
@linucks
Copy link
Contributor Author

linucks commented Jun 26, 2018

The changes were all sensible, so I've made most of them.

I agree that we need to think better about exiting as it causes an issue as the exit code as it's currently written doesn't have access to any AMPLE variables, so it can't clean up properly. I agree that Exceptions are probably the better way to go and then just have the main routine trap them and be responsible for exiting there. Again something for another day.

logger.info('*** Purge mode level %d specified - intermediate files will be deleted ***', optd['purge'])
try:
optd['purge'] = int(optd['purge'])
except ValueError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add a KeyError to the exception in case it's not defined.

@@ -412,13 +406,12 @@ def process_mr_options(optd):

# Model building programs
if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
if not (os.environ.has_key('warpbin')
and os.path.isfile(os.path.join(os.environ['warpbin'], "auto_tracing.sh"))):
if not ('warpbin' in os.environ and os.path.isfile(os.path.join(os.environ['warpbin'], "auto_tracing.sh"))):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing the same os.path.join twice, I would re-write this bit like:

if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
    auto_tracing_sh = os.path.join(os.environ['warpbin'], "auto_tracing.sh")
    if 'warpbin' in os.environ and os.path.isfile(auto_tracing_sh):
        logger.info('Using arpwarp script: %s', auto_tracing_sh)
    else:
        logger.warn('Cannot find arpwarp script! Disabling use of arpwarp.')
        optd['refine_rebuild_arpwarp'] = False
        optd['shelxe_rebuild_arpwarp'] = False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this, what happens if a user decides not to install arpwarp ... then the warpbin is not even in os.environ ... we need to be careful here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include this as well Jens

@fsimkovic
Copy link
Contributor

I maintain the belief that doing it now is little effort and it gets done. If this gets added to the infinitely-long TODO list, chances are it will never ever be correctly done. Surely it's not too much effort either to exchange the ample_util.exit_call with a sensible raise Exception statement.

@fsimkovic
Copy link
Contributor

Jens there are still two outstanding parts. Once a logger message and one the modified if statement.

@fsimkovic
Copy link
Contributor

I've sorted it myself now quickly.

@fsimkovic fsimkovic merged commit bd12c21 into rigdenlab:master Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants