def subgraph_translate3(read_path, write_dir):
    '''
    This function takes the metal-deficient structure and saves the all connected components (i.e. linkers)
    '''
    ase_struct = read(read_path)
    struct = pm.get_structure(ase_struct)
    n_atoms = len(struct.sites)
    sg = StructureGraph.with_local_env_strategy(struct, env.JmolNN(tol=.3))
    count = 1
    for i in range(n_atoms):
        for j in range(n_atoms):
            if i != j:
                try:
                    sg.alter_edge(i, j, new_weight=count)
                except:
                    pass
                count += 1

    A = sg.get_subgraphs_as_molecules(use_weights=True)

    ls = []
    count = 0
    for mol in A:
        if len(mol.sites) > 4:
            smiles = getSmiles(mol)
            ls.append(smiles)
            path = write_dir + 'mol_' + str(count) + '.xyz'
            saveMol(mol, path)
            count += 1
    return count, ls
Esempio n. 2
0
def get_mol_pymatgen(dataframe, nbrStruc):
    
    for i in range(nbrStruc):
        filename = dataframe.iloc[i,0]
        if (filename != "QAPHUK"):
            print(filename)
            parser = CifParser("../data/cif/{}.cif".format(filename))
            structure = parser.get_structures()[0]
            sg = StructureGraph.with_local_env_strategy(structure, locenv.JmolNN())
            my_molecules = sg.get_subgraphs_as_molecules()
            #molecule = MoleculeGraph.with_local_env_strategy(my_molecules,locenv.JmolNN())
            #print(molecule)
            #crystool.view(my_molecules)
            my_molecules = pyxyz.XYZ(my_molecules)
            #print(my_molecules)
            pyxyz.XYZ.write_file(my_molecules,"../data/xyz_pymatgen/{}.xyz".format(filename))
Esempio n. 3
0
 def __init__(self,
              root_dir,
              max_num_nbr=12,
              radius=8,
              nn_method=None,
              dmin=0,
              step=0.2,
              disable_save_torch=False,
              random_seed=123):
     self.root_dir = root_dir
     self.max_num_nbr, self.radius, self.nn_method = max_num_nbr, radius, nn_method
     self.disable_save_torch = disable_save_torch
     assert os.path.exists(root_dir), 'root_dir does not exist!'
     id_prop_file = os.path.join(self.root_dir, 'id_prop.csv')
     assert os.path.exists(id_prop_file), 'id_prop.csv does not exist!'
     with open(id_prop_file) as f:
         reader = csv.reader(f)
         self.id_prop_data = [[
             x.strip().replace('\ufeff', '') for x in row
         ] for row in reader]
     random.seed(random_seed)
     random.shuffle(self.id_prop_data)
     atom_init_file = os.path.join(self.root_dir, 'atom_init.json')
     assert os.path.exists(atom_init_file), 'atom_init.json does not exist!'
     self.ari = AtomCustomJSONInitializer(atom_init_file)
     self.gdf = GaussianDistance(dmin=dmin, dmax=self.radius, step=step)
     self.torch_data_path = os.path.join(self.root_dir, 'cifdata')
     if self.nn_method:
         if self.nn_method.lower() == 'minimumvirenn':
             self.nn_object = local_env.MinimumVIRENN()
         elif self.nn_method.lower() == 'voronoinn':
             self.nn_object = local_env.VoronoiNN()
         elif self.nn_method.lower() == 'jmolnn':
             self.nn_object = local_env.JmolNN()
         elif self.nn_method.lower() == 'minimumdistancenn':
             self.nn_object = local_env.MinimumDistanceNN()
         elif self.nn_method.lower() == 'minimumokeeffenn':
             self.nn_object = local_env.MinimumOKeeffeNN()
         elif self.nn_method.lower() == 'brunnernn_real':
             self.nn_object = local_env.BrunnerNN_real()
         elif self.nn_method.lower() == 'brunnernn_reciprocal':
             self.nn_object = local_env.BrunnerNN_reciprocal()
         elif self.nn_method.lower() == 'brunnernn_relative':
             self.nn_object = local_env.BrunnerNN_relative()
         elif self.nn_method.lower() == 'econnn':
             self.nn_object = local_env.EconNN()
         elif self.nn_method.lower() == 'cutoffdictnn':
             #requires a cutoff dictionary located in cgcnn/cut_off_dict.txt
             self.nn_object = local_env.CutOffDictNN(
                 cut_off_dict='cut_off_dict.txt')
         elif self.nn_method.lower() == 'critic2nn':
             self.nn_object = local_env.Critic2NN()
         elif self.nn_method.lower() == 'openbabelnn':
             self.nn_object = local_env.OpenBabelNN()
         elif self.nn_method.lower() == 'covalentbondnn':
             self.nn_object = local_env.CovalentBondNN()
         elif self.nn_method.lower() == 'crystalnn':
             self.nn_object = local_env.CrystalNN()
         else:
             raise ValueError('Invalid NN algorithm specified')
     else:
         self.nn_object = None