def csd_read(self, path_read, *, file_type='mol2'): ''' 从指定文件夹读取其中的cif文件,文件夹中只能有cif,然后以dict{cif文件名:cif中的分子}保存到: self.__Dict_mol_from_cif中 :param path_read: <class:str>用于专门储存Cifs的文件夹路径 :return: None ''' # 确定每个已经去除了溶剂的cif文件的名称和绝对路径 list_cif_names = os.listdir(path_read) list_path_cifs = glob.glob(os.path.join(path_read, '*.' + file_type)) count = -1 nub = 0 # 读取cif文件中的官能团 dict_crys_temp = dict() p_bar = tqdm(list_path_cifs) for path_cif_temp in p_bar: count += 1 try: mol_temp = io.CrystalReader(path_cif_temp)[0] dict_crys_temp[list_cif_names[count]] = mol_temp except: nub += 1 print(list_cif_names[count]) continue p_bar.set_description('Crystal.' + file_type + 'reading:') self.dict_crystal = dict_crys_temp print(nub)
def motif_cell_fromCIF(path, fill_cell=False): """ str (path to cif) --> np.array(s) shape (m,3), np.array(s) shape (3,3). Returns cartesian motif(s) and cell(s) in cif for use in the functions in this file. Returns a list [(motif1, cell1), ...] for all structures in the cif file. Optional param fill_cell (default False) will expand an asymmetric unit to fill the unit cell. This is necessary if the .cif contains an asymmetrix unit that is expanded by symmetry operations. """ from ccdc import io reader = io.CrystalReader(path) return [ motif_cell_fromCrystal(crystal, fill_cell=fill_cell) for crystal in reader ]
def create_multiple_pharmacophore_files(): # setting output directory out_dir = "testdata/pharmacophore_extension/PharmacophoreModel" if not os.path.exists(out_dir): os.mkdir(out_dir) # create files mols = io.CrystalReader( "testdata/pharmacophore_extension/provided_data/test_overlay.mol2") for mol in mols: lp = LigandPharmacophoreModel() lp.feature_definitions = ["ring_planar_projected"] lp.detect_from_ligand(mol) for feature in lp.detected_features: lp.add_feature(feature) lp.write(os.path.join(out_dir, f"{mol.identifier}.cm"))
def from_ligands(ligands, identifier, protein=None, settings=None): """ creates a Pharmacophore Model from a collection of overlaid ligands :param `ccdc,molecule.Molecule` ligands: ligands from which the Model is created :param str identifier: identifier for the Pharmacophore Model :param `ccdc.protein.Protein` protein: target system that the model has been created for :param `hotspots.hs_pharmacophore.PharmacophoreModel.Settings` settings: Pharmacophore Model settings :return: :class:`hotspots.hs_pharmacophore.PharmacophoreModel` >>> from ccdc.io import MoleculeReader >>> from hotspots.hs_pharmacophore import PharmacophoreModel >>> mols = MoleculeReader("ligand_overlay_model.mol2") >>> model = PharmacophoreModel.from_ligands(mols, "ligand_overlay_pharmacophore") >>> # write to .json and search in pharmit >>> model.write("model.json") """ cm_dic = crossminer_features() blank_grd = Grid.initalise_grid( [a.coordinates for l in ligands for a in l.atoms]) feature_dic = { "apolar": blank_grd.copy(), "acceptor": blank_grd.copy(), "donor": blank_grd.copy() } if not settings: settings = PharmacophoreModel.Settings() if isinstance(ligands[0], Molecule): temp = tempfile.mkdtemp() with io.MoleculeWriter(join(temp, "ligs.mol2")) as w: for l in ligands: w.write(l) ligands = list(io.CrystalReader(join(temp, "ligs.mol2"))) try: Pharmacophore.read_feature_definitions() except: raise ImportError("Crossminer is only available to CSD-Discovery") feature_definitions = [ fd for fd in Pharmacophore.feature_definitions.values() if fd.identifier != 'exit_vector' and fd.identifier != 'heavy_atom' and fd.identifier != 'hydrophobe' and fd.identifier != 'fluorine' and fd.identifier != 'bromine' and fd.identifier != 'chlorine' and fd.identifier != 'iodine' and fd.identifier != 'halogen' ] for fd in feature_definitions: detected = [fd.detect_features(ligand) for ligand in ligands] all_feats = [f for l in detected for f in l] if not all_feats: continue for f in all_feats: feature_dic[cm_dic[fd.identifier]].set_sphere( f.spheres[0].centre, f.spheres[0].radius, 1) features = [] for feat, feature_grd in feature_dic.items(): peaks = feature_grd.get_peaks(min_distance=4, cutoff=1) for p in peaks: coords = Coordinates(p[0], p[1], p[2]) projected_coordinates = None if feat == "donor" or feat == "acceptor": if protein: projected_coordinates = _PharmacophoreFeature.get_projected_coordinates( feat, coords, protein, settings) features.append( _PharmacophoreFeature( projected=None, feature_type=feat, feature_coordinates=coords, projected_coordinates=projected_coordinates, score_value=feature_grd.value_at_coordinate( coords, position=False), vector=None, settings=settings)) return PharmacophoreModel(settings, identifier=identifier, features=features, protein=protein, dic=feature_dic)
def run(self): ligands = io.CrystalReader(self.args.ligand_overlay) self.generate_pharmacophore(ligands, self.args.ref_pdb, self.args.output_directory)
def run(self): if not os.path.exists(self.args.output_directory): os.makedirs(self.args.output_directory) Pharmacophore.read_feature_definitions() self.crystals = list(io.CrystalReader(self.args.overlay_file)) if self.args.threshold <= 0.0: self.args.threshold = (len(self.crystals)) / 2.0 if self.args.feature_definitions: self.feature_definitions = [ v for k, v in Pharmacophore.feature_definitions.items() if k in self.args.feature_definitions ] else: self.feature_definitions = [ fd for fd in Pharmacophore.feature_definitions.values() if fd.identifier != 'exit_vector' and fd.identifier != 'heavy_atom' and fd.identifier != 'hydrophobe' ] complete_set_of_features = [] for fd in self.feature_definitions: detected = [fd.detect_features(c) for c in self.crystals] all_feats = [f for l in detected for f in l] if not all_feats: continue minx = min(f.spheres[0].centre.x() for f in all_feats) miny = min(f.spheres[0].centre.y() for f in all_feats) minz = min(f.spheres[0].centre.z() for f in all_feats) maxx = max(f.spheres[0].centre.x() for f in all_feats) maxy = max(f.spheres[0].centre.y() for f in all_feats) maxz = max(f.spheres[0].centre.z() for f in all_feats) g = utilities.Grid((minx - 1., miny - 1., minz - 1.), (maxx + 1, maxy + 1, maxz + 1), 0.2) spheres = [] for f in all_feats: if f.spheres[0] in spheres: g.set_sphere(f.spheres[0].centre, f.spheres[0].radius, 0) else: spheres.append(f.spheres[0]) g.set_sphere(f.spheres[0].centre, f.spheres[0].radius, 1) islands = g.islands(self.args.threshold) print('Feature: %s, max value %.2f, n_features %d' % (fd.identifier, g.extrema[1], len(islands))) for island in islands: # how do I make a feature from an island? Location of highest value indices = island.indices_at_value(island.extrema[1]) centre = indices[0] org = island.bounding_box[0] centre = tuple(org[i] + island.spacing * centre[i] for i in range(3)) radius = 1.0 # Any other spheres? if len(all_feats[0].spheres) > 1: # Pick all features which contain centre feat_dists = {} for f in all_feats: dist, feat = (GeometricDescriptors.point_distance( f.spheres[0].centre, centre), f) if feat_dists.has_key(dist): feat_dists[dist].append(feat) else: feat_dists.update({dist: [feat]}) feat_dists = collections.OrderedDict( sorted(feat_dists.items())) shortest_distance = feat_dists.keys()[0] if len(feat_dists[shortest_distance]) > 1: new_feat = [ Pharmacophore.Feature( fd, GeometricDescriptors.Sphere(centre, radius), feat_dists[shortest_distance][i].spheres[1]) for i in range(len(feat_dists[shortest_distance])) ] else: new_feat = [ Pharmacophore.Feature( fd, GeometricDescriptors.Sphere(centre, radius), feat_dists[shortest_distance][0].spheres[1]) ] else: new_feat = [ Pharmacophore.Feature( fd, GeometricDescriptors.Sphere(centre, radius)) ] complete_set_of_features.extend(new_feat) model = Pharmacophore.Query(complete_set_of_features) model.write(os.path.join(self.args.output_directory, 'model.cm'))