def make_monomer(length): """make an alkyl chain with two phenyl end caps >>> length = 7 >>> ap_monomer = AlkylPhenylPolymer.make_monomer(length) >>> ap_monomer.get_num_atoms() == 6 * 2 + length True >>> display(Draw.MolToImage(mol_with_atom_index(ap_monomer.to_rdkit_mol()), ... size=(700, 300))) """ alkane = init_building_block(smiles='F' + 'C' * length + 'F', functional_groups=[stk.FluoroFactory()]) benzene = init_building_block(smiles='FC1=CC=CC=C1', functional_groups=[stk.FluoroFactory()]) alkyl_phenyl = stk.ConstructedMolecule( topology_graph=stk.polymer.Linear( building_blocks=(alkane, benzene), repeating_unit='BAB', num_repeating_units=1, optimizer=stk.MCHammer(), )) return stk.BuildingBlock.init_from_molecule(alkyl_phenyl)
def __init__(self, num_repeating_units=2): lengths = [7, 12] repeating_unit = 'AB' def make_functional_group(n): return stk.GenericFunctionalGroup( atoms=tuple(stk.C(i) for i in range(n, n + 6)), bonders=(stk.C(n + 1), stk.C(n + 5)), deleters=tuple(stk.C(i) for i in range(n + 2, n + 5))) functional_groups = [make_functional_group(i) for i in (0, 6)] build_blocks = [ self.make_monomer(length).with_functional_groups(functional_groups) for length in lengths ] build_blocks[1] = build_blocks[1].with_rotation_about_axis( math.pi, build_blocks[1].get_direction(), build_blocks[1].get_centroid()) polymer = stk.ConstructedMolecule(topology_graph=stk.polymer.Linear( building_blocks=build_blocks, repeating_unit=repeating_unit, num_repeating_units=num_repeating_units, optimizer=stk.MCHammer(), )) # clean up the aromatic double bonds boundary_bonds = [ bond_info.get_bond() for bond_info in polymer.get_bond_infos() if bond_info.get_building_block_id() is None ] for bond in islice(boundary_bonds, 1, len(boundary_bonds), 2): bond._order = 2 self.polymer = ConstructedMoleculeTorsioned(polymer)
def main(): examples_output = 'aligner_directory' if not os.path.exists(examples_output): os.mkdir(examples_output) bb1 = stk.BuildingBlock('NCCN', [stk.PrimaryAminoFactory()]) bb2 = stk.BuildingBlock( smiles='O=CC(C=O)C=O', functional_groups=[stk.AldehydeFactory()], ) cage = stk.ConstructedMolecule( topology_graph=stk.cage.FourPlusSix( (bb1, bb2), optimizer=stk.MCHammer(num_steps=2000), ), ) mol_list = [ (stk.BuildingBlock('NCCNCCN'), (('N', 'N'), ), True), ( stk.BuildingBlock('CN1C=NC2=C1C(=O)N(C(=O)N2C)C'), (('N', 'N'), ('O', 'O'), ), True, ), (stk.BuildingBlock('C1=CN=CN=C1'), (('N', 'N'), ), True), (stk.BuildingBlock('c1ccccc1'), (('C', 'C'), ), True), (stk.BuildingBlock('C1CCCCC1'), (('C', 'C'), ), True), (cage, (('N', 'N'), ), True), ] _opt = stko.UFF() for i, (mol, pairs, uff_opt) in enumerate(mol_list): initial = mol.with_rotation_about_axis( 1.34, np.array((0, 0, 1)), np.array((0, 0, 0)), ) mol.write(os.path.join(examples_output, f'unaligned_{i}.mol')) initial.write(os.path.join(examples_output, f'init_{i}.mol')) aligner = stko.Aligner( initial_molecule=initial, matching_pairs=pairs, ) if uff_opt: mol = aligner.optimize(_opt.optimize(mol)) else: mol = aligner.optimize(mol) mol.write(os.path.join(examples_output, f'aligned_{i}.mol')) rmsd_calculator = stko.RmsdMappedCalculator(initial) rmsd = rmsd_calculator.get_results(mol).get_rmsd() print(f'molecule {i} RMSD: {rmsd}')
params=(CaseData( molecule=stk.ConstructedMolecule( topology_graph=stk.cage.EightPlusTwelve( building_blocks=( stk.BuildingBlock( smiles='BrC1=C(Br)[C+]=N1', functional_groups=[stk.BromoFactory()], ), stk.BuildingBlock( smiles=('Br[C+]1[C+2][C+](Br)[C+]2[C+](F)[C+2]' 'C2(Br)[C+2]1'), functional_groups=[stk.BromoFactory()], ), ), optimizer=stk.MCHammer( num_steps=150, random_seed=1000, ), ), ), smiles=('F[C+]1[C+2]C23[C+2][C+]4[C+2][C+](C5=C(N=[C+]5)C56[C+' '2][C+]7[C+2][C+](C8=C(N=[C+]8)C89[C+2][C+]%10[C+2][C+' '](C%11=C([C+]=N%11)C%11%12[C+2][C+]([C+2][C+](C%13=C2' '[C+]=N%13)[C+]%11[C+](F)[C+2]%12)C2=C(N=[C+]2)[C+]2[C' '+2][C+]%11C%12=C(N=[C+]%12)C%12%13[C+2][C+]([C+2][C+]' '(C%14=C([C+]=N%14)[C+]%14[C+2][C+](C%15=C7[C+]=N%15)[' 'C+]7[C+](F)[C+2]C7([C+2]%14)C7=C([C+]=N7)[C+]7[C+2][C' '+]([C+2]C%14([C+2][C+](F)[C+]7%14)C7=C4[C+]=N7)C4=C(N' '=[C+]4)C4([C+2]2)[C+2][C+](F)[C+]%114)[C+]%12[C+](F)[' 'C+2]%13)C2=C%10[C+]=N2)[C+]8[C+](F)[C+2]9)[C+]5[C+](F' ')[C+2]6)[C+]13'), ), ), ) def cage_opt_eight_plus_twelve(request):
CaseData( molecule=stk.BuildingBlock('CCCCCC'), unoptimised_energy=141.44622279628743, ), CaseData( molecule=stk.BuildingBlock('c1ccccc1'), unoptimised_energy=56.73128282588534, ), CaseData( molecule=stk.ConstructedMolecule(topology_graph=stk.polymer.Linear( building_blocks=( stk.BuildingBlock( smiles='BrCCBr', functional_groups=[stk.BromoFactory()], ), stk.BuildingBlock( smiles='BrCNCCBr', functional_groups=[stk.BromoFactory()], ), ), repeating_unit='AB', num_repeating_units=2, optimizer=stk.MCHammer(), ), ), unoptimised_energy=15002.946293854524, ), ], ) def case_molecule(request): return request.param
def main(): bb1 = stk.BuildingBlock('NCCN', [stk.PrimaryAminoFactory()]) bb2 = stk.BuildingBlock('O=CCC=O', [stk.AldehydeFactory()]) polymer = stk.ConstructedMolecule( stk.polymer.Linear(building_blocks=(bb1, bb2), repeating_unit="AB", orientations=(0, 0), num_repeating_units=1)) bb2 = stk.BuildingBlock('O=CC(C=O)C=O', [stk.AldehydeFactory()]) cage = stk.ConstructedMolecule(topology_graph=stk.cage.FourPlusSix( (bb1, bb2)), ) cage2 = stk.ConstructedMolecule(topology_graph=stk.cage.FourPlusSix( building_blocks=(bb1, bb2), optimizer=stk.MCHammer(), ), ) # Produce a Fe+2 atom with 6 functional groups. iron_atom = stk.BuildingBlock( smiles='[Fe+2]', functional_groups=(stk.SingleAtom(stk.Fe(0, charge=2)) for i in range(6)), position_matrix=[[0, 0, 0]], ) # Define coordinating ligand with dummy bromine groups and # metal coordinating functional groups. oct_bb = stk.BuildingBlock( smiles='C1=NC(C=NBr)=CC=C1', functional_groups=[ stk.SmartsFunctionalGroupFactory( smarts='[#6]~[#7X2]~[#35]', bonders=(1, ), deleters=(), ), stk.SmartsFunctionalGroupFactory( smarts='[#6]~[#7X2]~[#6]', bonders=(1, ), deleters=(), ), ], ) # Build iron complex with delta stereochemistry. iron_oct_delta = stk.ConstructedMolecule( topology_graph=stk.metal_complex.OctahedralDelta( metals=iron_atom, ligands=oct_bb, optimizer=stk.MCHammer(), ), ) # Assign Bromo functional groups to the metal complex. iron_oct_delta = stk.BuildingBlock.init_from_molecule( molecule=iron_oct_delta, functional_groups=[stk.BromoFactory()], ) # Define spacer building block. bb3 = stk.BuildingBlock( smiles=('C1=CC(C2=CC=C(Br)C=C2)=C' 'C=C1Br'), functional_groups=[stk.BromoFactory()], ) # Build an M4L6 Tetrahedron with a spacer. moc = stk.ConstructedMolecule( topology_graph=stk.cage.M4L6TetrahedronSpacer( building_blocks=( iron_oct_delta, bb3, ), optimizer=stk.MCHammer(), ), ) host = stk.ConstructedMolecule(topology_graph=stk.cage.FourPlusSix( building_blocks=( stk.BuildingBlock( smiles='NC1CCCCC1N', functional_groups=[ stk.PrimaryAminoFactory(), ], ), stk.BuildingBlock( smiles='O=Cc1cc(C=O)cc(C=O)c1', functional_groups=[stk.AldehydeFactory()], ), ), optimizer=stk.MCHammer(), ), ) guest1 = stk.host_guest.Guest( building_block=stk.BuildingBlock('BrBr'), displacement=(0., 3., 0.), ) guest2 = stk.host_guest.Guest( building_block=stk.BuildingBlock('C1CCCC1'), ) hg_complex = stk.ConstructedMolecule(topology_graph=stk.host_guest.Complex( host=stk.BuildingBlock.init_from_molecule(host), guests=(guest1, guest2), ), ) cycle = stk.ConstructedMolecule(topology_graph=stk.macrocycle.Macrocycle( building_blocks=(stk.BuildingBlock( smiles='[Br]CC[Br]', functional_groups=[stk.BromoFactory()], ), ), repeating_unit='A', num_repeating_units=8, optimizer=stk.MCHammer(), ), ) axle = stk.ConstructedMolecule(topology_graph=stk.polymer.Linear( building_blocks=( stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]), stk.BuildingBlock('BrCNCBr', [stk.BromoFactory()]), ), repeating_unit='AB', num_repeating_units=3, optimizer=stk.MCHammer(), )) rotaxane = stk.ConstructedMolecule(topology_graph=stk.rotaxane.NRotaxane( axle=stk.BuildingBlock.init_from_molecule(axle), cycles=(stk.BuildingBlock.init_from_molecule(cycle), ), repeating_unit='A', num_repeating_units=1, ), ) examples_output = 'output_directory' if not os.path.exists(examples_output): os.mkdir(examples_output) structures = [ ('bb1', bb1), ('bb2', bb2), ('bb3', bb3), ('polymer', polymer), ('cage', cage), ('cage2', cage2), ('m_iron_oct_delta', iron_oct_delta), ('m_moc', moc), ('hg_complex', hg_complex), ('cycle', cycle), ('axle', axle), ('rotaxane', rotaxane), ] # Run optimisations. for name, struct in structures: if 'm_' in name: rdkit_uff_energy = 'NA' else: rdkit_uff_energy = stko.UFFEnergy( ignore_inter_interactions=False).get_energy(struct) obabel_uff_energy = (stko.OpenBabelEnergy('uff').get_energy(struct)) struct.write(os.path.join(examples_output, f'obabel_{name}_unopt.mol')) opt = stko.OpenBabel( forcefield='uff', repeat_steps=10, sd_steps=20, cg_steps=20, ) opt_struct = opt.optimize(struct) opt_struct.write( os.path.join(examples_output, f'obabel_{name}_opt.mol')) if 'm_' in name: new_rdkit_uff_energy = 'NA' else: new_rdkit_uff_energy = stko.UFFEnergy( ignore_inter_interactions=False).get_energy(opt_struct) new_obabel_uff_energy = ( stko.OpenBabelEnergy('uff').get_energy(opt_struct)) print(f'{name}:\n' f'rdkit: {rdkit_uff_energy}, obabel: {obabel_uff_energy}\n' f'opt rdkit: {new_rdkit_uff_energy}, ' f'opt obabel: {new_obabel_uff_energy}\n')