def parse_derivative_string(string, quantity_dict):
    '''
    Assuming the string is of the form d(var1)d(var2), returns var1, var2.
    Raises ValueError if the string is not of this form, or if the vars
    are not keys in the quantity_dict, or if var2 is not a coordinate-like
    variable.
    '''
    match = derivative_prog.match(string)
    if match is None:
        raise ValueError('string is not in the form of a derivative')
    varname = match.group(1)
    coordname = match.group(2)
    if (varname not in quantity_dict.keys() or
            coordname not in quantity_dict.keys()):
        raise ValueError('variable in string not a valid quantity')
    return varname, coordname
Assuming the string is of the form d(var1)d(var2), returns var1, var2.
    Raises ValueError if the string is not of this form, or if the vars
    are not keys in the quantity_dict, or if var2 is not a coordinate-like
    variable.