geometric/run_json.py
def geometric_run_json(in_json_dict):
    """ Take a input dictionary loaded from json, and return an output dictionary for json """

    # Default logger configuration (prevents extra newline from being printed)
    logIni = pkg_resources.resource_filename(geometric.optimize.__name__, 'config/logJson.ini')
    import logging.config
    logging.config.fileConfig(logIni,disable_existing_loggers=False)

    # Set a temporary logger to capture output
    log_stream = RawStreamHandler(stream=StringIO())
    logger.addHandler(log_stream)

    input_opts = parse_input_json_dict(in_json_dict)
    M, engine = geometric.optimize.get_molecule_engine(**input_opts)

    # Get initial coordinates in bohr
    coords = M.xyzs[0].flatten() * geometric.nifty.ang2bohr

    # Read in the constraints
    constraints_dict = input_opts.get('constraints', {})
    if "scan" in constraints_dict:
        raise KeyError("The constraint 'scan' keyword is not yet supported by the JSON interface")

    constraints_string = make_constraints_string(constraints_dict)
    Cons, CVals = None, None
    if constraints_string:
        Cons, CVals = geometric.prepare.parse_constraints(M, constraints_string)

    # set up the internal coordinate system
    coordsys = input_opts.get('coordsys', 'tric')
    CoordSysDict = {
        'cart': (geometric.internal.CartesianCoordinates, False, False),
        'prim': (geometric.internal.PrimitiveInternalCoordinates, True, False),
        'dlc': (geometric.internal.DelocalizedInternalCoordinates, True, False),
        'hdlc': (geometric.internal.DelocalizedInternalCoordinates, False, True),
        'tric': (geometric.internal.DelocalizedInternalCoordinates, False, False)
    }

    CoordClass, connect, addcart = CoordSysDict[coordsys.lower()]
    IC = CoordClass(
        M,
        build=True,
        connect=connect,
        addcart=addcart,
        constraints=Cons,
        cvals=CVals[0] if CVals is not None else None)

    # Print out information about the coordinate system
    if isinstance(IC, geometric.internal.CartesianCoordinates):
        logger.info("%i Cartesian coordinates being used\n" % (3 * M.na))
    else:
        logger.info("%i internal coordinates being used (instead of %i Cartesians)\n" % (len(IC.Internals), 3 * M.na))
    logger.info(IC)
    logger.info("\n")

    params = geometric.optimize.OptParams(**input_opts)

    try:
        # Run the optimization
        if Cons is None:
            # Run a standard geometry optimization
            geometric.optimize.Optimize(coords, M, IC, engine, None, params)
        else:
            # Run a constrained geometry optimization
            if isinstance(IC, (geometric.internal.CartesianCoordinates,
                               geometric.internal.PrimitiveInternalCoordinates)):
                raise RuntimeError("Constraints only work with delocalized internal coordinates")
            for ic, CVal in enumerate(CVals):
                if len(CVals) > 1:
                    logger.info("---=== Scan %i/%i : Constrained Optimization ===---\n" % (ic + 1, len(CVals)))
                IC = CoordClass(M, build=True, connect=connect, addcart=addcart, constraints=Cons, cvals=CVal)
                IC.printConstraints(coords, thre=-1)
                geometric.optimize.Optimize(coords, M, IC, engine, None, params)

        out_json_dict = get_output_json_dict(in_json_dict, engine.schema_traj)
        out_json_dict["success"] = True

    except Exception as e:
        out_json_dict = get_output_json_dict(in_json_dict, engine.schema_traj)
        out_json_dict["success"] = False
        out_json_dict["error"] = {
            "error_type": "unknown",
            "error_message": "geomeTRIC run_json error:\n" + traceback.format_exc()
        }

    # Grab logging and pop logger
    out_json_dict["stdout"] = log_stream.stream.getvalue()
    log_stream.close()
    logger.handlers.remove(log_stream)

    return out_json_dict
 Take a input dictionary loaded from json, and return an output dictionary for json 
Take a input dictionary loaded from json, and return an output dictionary for json
Take a input dictionary loaded from json and return an output dictionary for json
def geometric_run_json(in_json_dict):
    logIni = pkg_resources.resource_filename(geometric.optimize.__name__, 'config/logJson.ini')
    import logging.config
    logging.config.fileConfig(logIni,disable_existing_loggers=False)
    log_stream = RawStreamHandler(stream=StringIO())
    logger.addHandler(log_stream)
    input_opts = parse_input_json_dict(in_json_dict)
    M, engine = geometric.optimize.get_molecule_engine(**input_opts)
    coords = M.xyzs[0].flatten() * geometric.nifty.ang2bohr
    constraints_dict = input_opts.get('constraints', {})
    if "scan" in constraints_dict:
        raise KeyError("The constraint 'scan' keyword is not yet supported by the JSON interface")
    constraints_string = make_constraints_string(constraints_dict)
    Cons, CVals = None, None
    if constraints_string:
        Cons, CVals = geometric.prepare.parse_constraints(M, constraints_string)
    coordsys = input_opts.get('coordsys', 'tric')
    CoordSysDict = {
        'cart': (geometric.internal.CartesianCoordinates, False, False),
        'prim': (geometric.internal.PrimitiveInternalCoordinates, True, False),
        'dlc': (geometric.internal.DelocalizedInternalCoordinates, True, False),
        'hdlc': (geometric.internal.DelocalizedInternalCoordinates, False, True),
        'tric': (geometric.internal.DelocalizedInternalCoordinates, False, False)
    }
    CoordClass, connect, addcart = CoordSysDict[coordsys.lower()]
    IC = CoordClass(
        M,
        build=True,
        connect=connect,
        addcart=addcart,
        constraints=Cons,
        cvals=CVals[0] if CVals is not None else None)
    if isinstance(IC, geometric.internal.CartesianCoordinates):
        logger.info("%i Cartesian coordinates being used\n" % (3 * M.na))
    else:
        logger.info("%i internal coordinates being used (instead of %i Cartesians)\n" % (len(IC.Internals), 3 * M.na))
    logger.info(IC)
    logger.info("\n")
    params = geometric.optimize.OptParams(**input_opts)
    try:
        if Cons is None:
            geometric.optimize.Optimize(coords, M, IC, engine, None, params)
        else:
            if isinstance(IC, (geometric.internal.CartesianCoordinates,
                               geometric.internal.PrimitiveInternalCoordinates)):
                raise RuntimeError("Constraints only work with delocalized internal coordinates")
            for ic, CVal in enumerate(CVals):
                if len(CVals) > 1:
                    logger.info("---=== Scan %i/%i : Constrained Optimization ===---\n" % (ic + 1, len(CVals)))
                IC = CoordClass(M, build=True, connect=connect, addcart=addcart, constraints=Cons, cvals=CVal)
                IC.printConstraints(coords, thre=-1)
                geometric.optimize.Optimize(coords, M, IC, engine, None, params)
        out_json_dict = get_output_json_dict(in_json_dict, engine.schema_traj)
        out_json_dict["success"] = True
    except Exception as e:
        out_json_dict = get_output_json_dict(in_json_dict, engine.schema_traj)
        out_json_dict["success"] = False
        out_json_dict["error"] = {
            "error_type": "unknown",
            "error_message": "geomeTRIC run_json error:\n" + traceback.format_exc()
        }
    out_json_dict["stdout"] = log_stream.stream.getvalue()
    log_stream.close()
    logger.handlers.remove(log_stream)
    return out_json_dict
def geometric_run_json ( in_json_dict ) : logIni = pkg_resources . resource_filename ( geometric . optimize . __name__ , 'config/logJson.ini' ) import logging . config logging . config . fileConfig ( logIni , disable_existing_loggers = False ) log_stream = RawStreamHandler ( stream = StringIO ( ) ) logger . addHandler ( log_stream ) input_opts = parse_input_json_dict ( in_json_dict ) M , engine = geometric . optimize . get_molecule_engine ( ** input_opts ) coords = M . xyzs [ 0 ] . flatten ( ) * geometric . nifty . ang2bohr constraints_dict = input_opts . get ( 'constraints' , { } ) if "scan" in constraints_dict : raise KeyError ( "The constraint 'scan' keyword is not yet supported by the JSON interface" ) constraints_string = make_constraints_string ( constraints_dict ) Cons , CVals = None , None if constraints_string : Cons , CVals = geometric . prepare . parse_constraints ( M , constraints_string ) coordsys = input_opts . get ( 'coordsys' , 'tric' ) CoordSysDict = { 'cart' : ( geometric . internal . CartesianCoordinates , False , False ) , 'prim' : ( geometric . internal . PrimitiveInternalCoordinates , True , False ) , 'dlc' : ( geometric . internal . DelocalizedInternalCoordinates , True , False ) , 'hdlc' : ( geometric . internal . DelocalizedInternalCoordinates , False , True ) , 'tric' : ( geometric . internal . DelocalizedInternalCoordinates , False , False ) } CoordClass , connect , addcart = CoordSysDict [ coordsys . lower ( ) ] IC = CoordClass ( M , build = True , connect = connect , addcart = addcart , constraints = Cons , cvals = CVals [ 0 ] if CVals is not None else None ) if isinstance ( IC , geometric . internal . CartesianCoordinates ) : logger . info ( "%i Cartesian coordinates being used\n" % ( 3 * M . na ) ) else : logger . info ( "%i internal coordinates being used (instead of %i Cartesians)\n" % ( len ( IC . Internals ) , 3 * M . na ) ) logger . info ( IC ) logger . info ( "\n" ) params = geometric . optimize . OptParams ( ** input_opts ) try : if Cons is None : geometric . optimize . Optimize ( coords , M , IC , engine , None , params ) else : if isinstance ( IC , ( geometric . internal . CartesianCoordinates , geometric . internal . PrimitiveInternalCoordinates ) ) : raise RuntimeError ( "Constraints only work with delocalized internal coordinates" ) for ic , CVal in enumerate ( CVals ) : if len ( CVals ) > 1 : logger . info ( "---=== Scan %i/%i : Constrained Optimization ===---\n" % ( ic + 1 , len ( CVals ) ) ) IC = CoordClass ( M , build = True , connect = connect , addcart = addcart , constraints = Cons , cvals = CVal ) IC . printConstraints ( coords , thre = - 1 ) geometric . optimize . Optimize ( coords , M , IC , engine , None , params ) out_json_dict = get_output_json_dict ( in_json_dict , engine . schema_traj ) out_json_dict [ "success" ] = True except Exception as e : out_json_dict = get_output_json_dict ( in_json_dict , engine . schema_traj ) out_json_dict [ "success" ] = False out_json_dict [ "error" ] = { "error_type" : "unknown" , "error_message" : "geomeTRIC run_json error:\n" + traceback . format_exc ( ) } out_json_dict [ "stdout" ] = log_stream . stream . getvalue ( ) log_stream . close ( ) logger . handlers . remove ( log_stream ) return out_json_dict
Take a input dictionary loaded from json, and return an output dictionary for json
Take a input dictionary loaded from json and return an output dictionary for json
""" Take a input dictionary loaded from json, and return an output dictionary for json """ # Default logger configuration (prevents extra newline from being printed) # Set a temporary logger to capture output # Get initial coordinates in bohr # Read in the constraints # set up the internal coordinate system # Print out information about the coordinate system # Run the optimization # Run a standard geometry optimization # Run a constrained geometry optimization # Grab logging and pop logger
in_json_dict