geometric/run_json.py
def make_constraints_string(constraints_dict):
    """ Convert the new constraints dict format into the original string format """

    constraints_dict = copy.deepcopy(constraints_dict)

    key_fields = {"freeze": ("type", ), "set": ("type", "value"), "scan": ("type", "start", "stop", "steps")}
    spec_numbers = {"xyz": None, "distance": 2, "angle": 3, "dihedral": 4}

    constraints_repr = []

    # Parse overall constraints
    for key, constraints_list in constraints_dict.items():

        if key not in key_fields:
            raise KeyError("Constraints key %s is not recognized" % key)
        key_args = key_fields[key]

        # Parse individual constraints within a key
        constraints_repr.append("$" + key)
        for constraint in constraints_list:

            # Check keys
            missing = set(key_args) - set(constraint.keys())
            if missing:
                raise KeyError("Constraint type '%s' requires fields '%s', found '%s'" % (key, key_args,
                                                                                          constraint.keys()))

            # Check types and length
            constraint_type = constraint["type"].lower()
            if constraint_type not in spec_numbers:
                raise KeyError("Constraint type '%s' not recognized." % constraint["type"][0])

            spec_length = spec_numbers[constraint_type]
            if (spec_length is not None) and (len(constraint["indices"]) != spec_length):
                raise ValueError("Expected constraint of type '%s' to have length '%d', found %s." %
                                 (constraint_type, spec_length, str(constraint["indices"])))

            # Translate distance bohr to angstrom
            if constraint["type"] == "distance":
                if key == "scan":
                    constraint["start"] *= geometric.nifty.bohr2ang
                    constraint["stop"] *= geometric.nifty.bohr2ang
                elif key == "set":
                    constraint["value"] *= geometric.nifty.bohr2ang

            # Get base values
            const_rep = [constraint_type]
            if constraint["type"] == "xyz":
                # the "xyz" type expects one index block with no spaces
                const_rep.append(commadash(constraint["indices"]))
            else:
                # Add one to make it consistent with normal input
                const_rep.extend([x + 1 for x in constraint["indices"]])
            for k in key_args[1:]:
                const_rep.append(constraint[k])

            rep = " ".join(map(str, const_rep))

            constraints_repr.append(rep)

    return "\n".join(constraints_repr)
 Convert the new constraints dict format into the original string format 
Convert the new constraints dict format into the original string format
Convert the new constraints dict format into the original string format
def make_constraints_string(constraints_dict):
    constraints_dict = copy.deepcopy(constraints_dict)
    key_fields = {"freeze": ("type", ), "set": ("type", "value"), "scan": ("type", "start", "stop", "steps")}
    spec_numbers = {"xyz": None, "distance": 2, "angle": 3, "dihedral": 4}
    constraints_repr = []
    for key, constraints_list in constraints_dict.items():
        if key not in key_fields:
            raise KeyError("Constraints key %s is not recognized" % key)
        key_args = key_fields[key]
        constraints_repr.append("$" + key)
        for constraint in constraints_list:
            missing = set(key_args) - set(constraint.keys())
            if missing:
                raise KeyError("Constraint type '%s' requires fields '%s', found '%s'" % (key, key_args,
                                                                                          constraint.keys()))
            constraint_type = constraint["type"].lower()
            if constraint_type not in spec_numbers:
                raise KeyError("Constraint type '%s' not recognized." % constraint["type"][0])
            spec_length = spec_numbers[constraint_type]
            if (spec_length is not None) and (len(constraint["indices"]) != spec_length):
                raise ValueError("Expected constraint of type '%s' to have length '%d', found %s." %
                                 (constraint_type, spec_length, str(constraint["indices"])))
            if constraint["type"] == "distance":
                if key == "scan":
                    constraint["start"] *= geometric.nifty.bohr2ang
                    constraint["stop"] *= geometric.nifty.bohr2ang
                elif key == "set":
                    constraint["value"] *= geometric.nifty.bohr2ang
            const_rep = [constraint_type]
            if constraint["type"] == "xyz":
                const_rep.append(commadash(constraint["indices"]))
            else:
                const_rep.extend([x + 1 for x in constraint["indices"]])
            for k in key_args[1:]:
                const_rep.append(constraint[k])
            rep = " ".join(map(str, const_rep))
            constraints_repr.append(rep)
    return "\n".join(constraints_repr)
def make_constraints_string ( constraints_dict ) : constraints_dict = copy . deepcopy ( constraints_dict ) key_fields = { "freeze" : ( "type" , ) , "set" : ( "type" , "value" ) , "scan" : ( "type" , "start" , "stop" , "steps" ) } spec_numbers = { "xyz" : None , "distance" : 2 , "angle" : 3 , "dihedral" : 4 } constraints_repr = [ ] for key , constraints_list in constraints_dict . items ( ) : if key not in key_fields : raise KeyError ( "Constraints key %s is not recognized" % key ) key_args = key_fields [ key ] constraints_repr . append ( "$" + key ) for constraint in constraints_list : missing = set ( key_args ) - set ( constraint . keys ( ) ) if missing : raise KeyError ( "Constraint type '%s' requires fields '%s', found '%s'" % ( key , key_args , constraint . keys ( ) ) ) constraint_type = constraint [ "type" ] . lower ( ) if constraint_type not in spec_numbers : raise KeyError ( "Constraint type '%s' not recognized." % constraint [ "type" ] [ 0 ] ) spec_length = spec_numbers [ constraint_type ] if ( spec_length is not None ) and ( len ( constraint [ "indices" ] ) != spec_length ) : raise ValueError ( "Expected constraint of type '%s' to have length '%d', found %s." % ( constraint_type , spec_length , str ( constraint [ "indices" ] ) ) ) if constraint [ "type" ] == "distance" : if key == "scan" : constraint [ "start" ] *= geometric . nifty . bohr2ang constraint [ "stop" ] *= geometric . nifty . bohr2ang elif key == "set" : constraint [ "value" ] *= geometric . nifty . bohr2ang const_rep = [ constraint_type ] if constraint [ "type" ] == "xyz" : const_rep . append ( commadash ( constraint [ "indices" ] ) ) else : const_rep . extend ( [ x + 1 for x in constraint [ "indices" ] ] ) for k in key_args [ 1 : ] : const_rep . append ( constraint [ k ] ) rep = " " . join ( map ( str , const_rep ) ) constraints_repr . append ( rep ) return "\n" . join ( constraints_repr )
Convert the new constraints dict format into the original string format
Convert the new constraints dict format into the original string format
""" Convert the new constraints dict format into the original string format """ # Parse overall constraints # Parse individual constraints within a key # Check keys # Check types and length # Translate distance bohr to angstrom # Get base values # the "xyz" type expects one index block with no spaces # Add one to make it consistent with normal input
constraints_dict