Ejemplo n.º 1
0
def unitCellQuerySettings(cellLengths, cellAngles, centring, absAngTol,
                          percentLenTol):
    """
    :param cellLengths: float
    :param cellAngles: float
    :param centring: float
    :param absAngTol: float
    :param percentLenTol: float
    :return: ccdc.search.SearchHit
    """
    logger.info("Created cell angles" + str(cellAngles))
    logger.info("Created cell lengths" + str(cellLengths))
    logger.info("Set to centering" + str(centring))

    query = ReducedCellSearch.Query(angles=cellAngles,
                                    lengths=cellLengths,
                                    lattice_centring=centring)
    searcher = ReducedCellSearch(query)

    if (percentLenTol != None):
        searcher.settings.percent_length_tolerance = percentLenTol
    if (absAngTol != None):
        searcher.settings.absolute_angle_tolerance = absAngTol

    return retrieveHits(searcher)
Ejemplo n.º 2
0
def searchCellAngles(alpha, beta, gamma):
    """
    @deprecated:
    :param alpha: float
    :param beta: float
    :param gamma: float
    :return: ccdc.search.SearchHit
    """
    cellAngles = crystal.CellAngles(alpha, beta, gamma)
    query = ReducedCellSearch.Query(angles=cellAngles)
    searcher = ReducedCellSearch(query)
    return retrieveHits(searcher)
Ejemplo n.º 3
0
def searchCellVals(a, b, c):
    """
    The generic lattice centering does not work...
    @deprecated: need to set crystal system
    :param a: float
    :param b: float
    :param c: float 
    :return: ccdc.search.SearchHit
    """
    cellLen = crystal.CellLengths(a, b, c)
    query = ReducedCellSearch.Query(lengths=cellLen)
    specifics = query._get_query()
    searcher = ReducedCellSearch(query)
    return retrieveHits(searcher)
Ejemplo n.º 4
0
def unitCellQuery(cellLengths, cellAngles, centring):
    """
    :param cellLengths: float
    :param cellAngles: float
    :param centring: ChemLin.Spacegroupcentering TODO: validation?
    :return: ccdc.search.SearchHit
    """
    logger.info("Created cell angles"+ str(cellAngles))
    logger.info("Created cell lengths" + str(cellLengths))
    logger.info("Set to centering" + str(centring))

    query = ReducedCellSearch.Query(angles=cellAngles, lengths=cellLengths, lattice_centring=centring)
    searcher = ReducedCellSearch(query)

    return retrieveHits(searcher)
Ejemplo n.º 5
0
def my_reduced_cell_search(
    user_a,
    user_b,
    user_c,
    user_alpha,
    user_beta,
    user_gamma,
    user_centring,
    database=csdsql_database_path,
    filename=json_search_results_path,
    length_tolerance=1.5,
    angle_tolerance=2.0,
):
    # lattice_centring_dict = {
    #                 'P':'primitive','C':'C-centred','F':'F-centred','I':'I-centred',
    #                 'R':'R-obverse','?':'unknown centring','B':'B-centred','A':'A-centred'}

    # build the search
    query = ReducedCellSearch.Query(
        CellLengths(a=user_a, b=user_b, c=user_c),
        CellAngles(alpha=user_alpha, beta=user_beta, gamma=user_gamma),
        user_centring,
    )
    searcher = ReducedCellSearch(query=query, )
    searcher.settings.absolute_angle_tolerance = float(length_tolerance)
    searcher.settings.percent_length_tolerance = float(angle_tolerance)
    hits = searcher.search(database=database)  # /inhouse.csdsql

    # load in the cif database as a list of dictionaries
    with open(json_database_path, "r") as filehandle:
        data = filehandle.read()
    data = json.loads(data)

    search_results = []  # the list of dicts to export as json
    for h in hits:
        for i in data:
            if i["hash"] == h.identifier:
                print(i["hash"])
                search_results.append(i)
            elif i["_database_code_CSD"] == h.identifier:
                print(h.identifier)
                search_results.append(i)
    parsed_cifs_2_json(search_results,
                       filename="../database_files/search_results.json")

    print(str(len(hits)) + " hits found.")
Ejemplo n.º 6
0
 def search(self):
     # searches the csd data base for a crystal with known parameters returns best result
     cellA = namedtuple('CellAngles', ['alpha', 'beta', 'gamma']) # create a named tuple for ccdc module
     angles = list(self.angles) # make a list of angles
     more_angles = cellA(float(angles[0]),float(angles[1]),float(angles[2])) # append angles to the tuple
     cellL = namedtuple('CellLengths',['a','b','c'])
     cell_lengths = self.cell_lengths
     more_lengths = cellL(float(cell_lengths[0]),float(cell_lengths[1]),float(cell_lengths[2]))
     
     query = ReducedCellSearch.Query(lengths = more_lengths,angles = more_angles ,lattice_centring = 'primitive' )
     searcher = ReducedCellSearch(query)
     
     hits = searcher.search() # search for all hits
     i = 0
     while i < float(self.numhits):
         h = hits[i]
         print h.identifier, h.crystal.cell_lengths, h.crystal.cell_angles, h.crystal.lattice_centring # print the best result 
         i += 1