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(angles[0],angles[1],angles[2]) # append angles to the tuple cellL = namedtuple('CellLengths',['a','b','c']) cell_lengths = self.cell_lengths more_lengths = cellL(cell_lengths[0],cell_lengths[1],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 h = hits[0] # top hit print h.identifier, h.crystal.cell_lengths, h.crystal.cell_angles, h.crystal.lattice_centring # print the best result
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.")
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