# apbs module for the FreeMOL library

# executable path
import traceback
import os
import freemol

_apbs_exe = None
_psize_py = None

def validate():
    '''
    make sure that the FREEMOL environment variable is defined and
    that it contains a valid directory path

    returns 1 if valid, 0 if not
    '''
    ok = 0
    global _apbs_exe
    if _apbs_exe != None: # _apbs_exe assigned, so presume valid
        ok = 1
    elif os.environ.has_key('FREEMOL'):
        test_path = os.path.join(os.environ['FREEMOL'],"bin","apbs.exe")
        if os.path.exists(test_path) and os.path.isfile(test_path):
            _apbs_exe = freemol.quote_exe(test_path)
            ok = 1
    global _psize_py
    if _psize_py != None: # _psize_py assigned, so presume valid
        ok = 1
    elif os.environ.has_key('FREEMOL'):
        test_path = os.path.join(os.environ['FREEMOL'],"share","apbs","psize.py")
        if os.path.exists(test_path) and os.path.isfile(test_path):
            _psize_py = test_path
            ok = 1
    return ok

def get_exe_path():
    if _apbs_exe == None:
        validate()
    return _apbs_exe

def get_psize_path():
    if _psize_py == None:
        validate()
    return _psize_py
