Team Ai
Modelpublic

OneScience-Group/flex_ddG_tutorial

sourceHugging Facemitupdated 29d agoView on Hugging Face
0likes27downloads
flex_ddg_db3.py49 linesDownload Raw Back to scripts
1#!/usr/bin/env python32 3'''Small helpers shared by analyze_flex_ddG.py and extract_structures.py.4 5Standard library only, so that extract_structures.py keeps running without numpy or pandas.6'''7 8import re9import sqlite310 11# Rosetta records the full option list it was invoked with in the "protocols" table of every12# features database it writes, so the stride a run actually used can be read back out of the13# output instead of being remembered and re-typed by hand.14_stride_re = re.compile( r'backrub_trajectory_stride[= ]+(\d+)' )15 16def trajectory_stride_from_db3( db3_file ):17    '''The backrub_trajectory_stride the run in db3_file was launched with.18 19    Returns None if it cannot be determined, which happens for databases written by Rosetta20    versions that predate the protocols table, or if the stride was left at the XML default21    instead of being passed on the command line. Callers should fall back to a default and say22    so, because the stride does not affect any energy -- it only labels the checkpoints, so a23    wrong value silently mislabels every row (and misnames every extracted PDB) rather than24    causing a visible failure.25    '''26    try:27        conn = sqlite3.connect( 'file:%s?mode=ro' % db3_file, uri = True )28    except sqlite3.Error:29        return None30 31    try:32        try:33            rows = conn.execute( 'SELECT specified_options, command_line FROM protocols' ).fetchall()34        except sqlite3.Error:35            return None36 37        strides = set()38        for row in rows:39            for field in row:40                if field:41                    strides.update( int(m) for m in _stride_re.findall( field ) )42    finally:43        conn.close()44 45    # More than one distinct value means the database mixes runs; we cannot label it correctly.46    if len( strides ) == 1:47        return strides.pop()48    return None49