lukasturcani / stk

A Python library which allows construction and manipulation of complex molecules, as well as automatic molecular design and the creation of molecular databases.
https://stk.readthedocs.io/
MIT License
252 stars 47 forks source link

Get lattice parameters of MOF #483

Open KP-303 opened 1 year ago

KP-303 commented 1 year ago

I would like to generate a MOF and then write this to a cif file. so I can pass it into mofdescribe (the features I want to calculate require the unit cell info). To do this I need info on the periodicity but I don't know how to get this. I generate a MOF using your example code:

Produce a Pd+2 atom with 4 functional groups.

palladium_atom = stk.BuildingBlock( smiles='[Pd+2]', functional_groups=( stk.SingleAtom(stk.Pd(0, charge=2)) for i in range(4) ), position_matrix=[[0., 0., 0.]], )

Build a building block with two functional groups using

the SmartsFunctionalGroupFactory.

bb1 = stk.BuildingBlock( smiles=( 'C1=NC=CC(C2=CC=CC(C3=C' 'C=NC=C3)=C2)=C1' ), functional_groups=[ stk.SmartsFunctionalGroupFactory( smarts='[#6]~[#7X2]~[#6]', bonders=(1, ), deleters=(), ), ], )

cage1 = stk.ConstructedMolecule( stk.cage.M2L4Lantern( building_blocks=(palladium_atom, bb1),

Ensure that bonds between the

    # GenericFunctionalGroups of the ligand and the
    # SingleAtom functional groups of the metal are
    # dative.
    reaction_factory=stk.DativeReactionFactory(
        stk.GenericReactionFactory(
            bond_orders={
                frozenset({
                    stk.GenericFunctionalGroup,
                    stk.SingleAtom,
                }): 9,
            },
        ),
    ),
),

)

stk.MolWriter().write(cage1, "test.xyz")

If I understand correctly, it should be possible to get the lattice parameters from this, because I specify a topology when building the MOF, but I don't know how to do it. Maybe the directions of the lattice vectors and their relative lengths, and the angles, are known for each topology, then I can measure the size of the molecule to scale the lattice vectors? I would optimise the structure first. It seems like the organic cage building option gives lattice parameters.

I've read the docs but not found the answer sorry.

andrewtarzia commented 1 year ago

Hello and welcome!

So, it is possible to do what you want to do, see accessing periodic information in https://stk.readthedocs.io/en/stable/stk.molecular.topology_graphs.cof.cof.html for an example on COFs. Also see this issue for some more information: https://github.com/lukasturcani/stk/issues/461

However, the code you sent is constructing an M2L4 metal-organic cage, not a MOF. Cages are not periodic structures and, therefore, what you are trying to do here is not appropriate. You need to construct a molecule using a periodic topology graph, not all topology graphs are periodic. If you can clarify what you would like to construct, we can help you further.

KP-303 commented 1 year ago

Thanks I'll read that. I would like to build a Metal Organic Framework and get the lattice info as well as the .xyz structure so I can create a pymatgen structure object out of it. I don't have a specific topology in mind; I would like to be able to do this for any of the common MOF topologies.

KP-303 commented 1 year ago

I've had a closer look but I don't know how to build a MOF sorry. The metal organic cage topologies are non periodic, but the COF topologies don't have metals and look to all be 2D. Should I build a custom MOF topology? The documentation on adding topologies doesn't mention periodicity but I guess I can combine the code for a metal organic cage with the periodicity of a COF?

Thanks

andrewtarzia commented 1 year ago

So, stk does not have any limitations in terms of what building block you place on a topology graph, in terms of chemistry. You can place a metal atom in a COF topology, the same way you do for a MOC topology. See here for an example of my placing cages in a COF topology to make a polymer of MOCs: https://github.com/andrewtarzia/stk-examples/blob/main/polymerised_mocs/ligand_connected.py

But, your other point is correct - stk does not currently have 3D MOFs. We have not really given it a full go yet to implement the appropriate rotations/alignments required for MOF generation - but the issue is discussed #204 #421 - Therefore, depending on what topology you intend on building, you will need to implement a custom topology graph, which we are happy to help with if you come across issues.

KP-303 commented 1 year ago

Thanks, I'll have a go.