def smi2cm(m): m1 = Chem.MolFromSmiles(m) m = Chem.AddHs(m1) AllChem.EmbedMolecule(m,AllChem.ETKDG()) n_atoms = m.GetNumAtoms() m1=Chem.MolToMolBlock(m) m1=m1.split() axis=[] atom_list=[] for i in range(0,n_atoms): axis.append([float(m1[13+16*i]),float(m1[14+i*16]),float(m1[15+16*i])]) atom_list.append(m1[16+16*i]) feat=CoulombMatrix() mole=(atom_list,axis) feat.fit([mole]) t=feat.transform([mole])[0] CM=t.reshape((n_atoms,n_atoms)).tolist() return CM
name='mol'+ str(mol_no) xyz_dict[name]=a index=index+atom_nums+2 mol_no=mol_no-1 atom_list=[] axis=[] for j in range(0,len(a)): atom=a[j].split() atom_list.append(atom[0]) axis.append([float(atom[1]),float(atom[2]),float(atom[3])]) feat=CoulombMatrix() mole=(atom_list,axis) feat.fit([mole]) CM=feat.transform([mole])[0] t=CM.reshape((atom_nums,atom_nums)).tolist() CM_dict.append(t) fd.close() sio.savemat('CM.mat',{'CM':CM_dict}) else: #smi to coordination and coulomb matrix filepath=input("what's sdf filename?") #get CM def smi2cm(m): m1 = Chem.MolFromSmiles(m) m = Chem.AddHs(m1) AllChem.EmbedMolecule(m,AllChem.ETKDG()) n_atoms = m.GetNumAtoms() m1=Chem.MolToMolBlock(m) m1=m1.split()
] HCN_CONNS = { 0: {1: '1'}, 1: {0: '1', 2: '3'}, 2: {1: '3'}, } if __name__ == "__main__": # Example of generating the Coulomb matrix with just elements and coords # for a single example molecule. feat = CoulombMatrix() H2 = (H2_ELES, H2_COORDS) feat.fit([H2]) print("Transformed H2") print(feat.transform([H2])) print() # Example of generating the Coulomb matrix with just elements and coords # for multiple molecules. feat = CoulombMatrix() HCN = (HCN_ELES, HCN_COORDS) feat.fit([H2, HCN]) print("Transformed H2") print(feat.transform([H2])) print("H2 and HCN transformed") print(feat.transform([H2, HCN])) print() # Example of generating the Coulomb matrix with elements, coords, and # connections.