Skip to content

Instantly share code, notes, and snippets.

@andrewtarzia
Last active November 15, 2023 17:42
Show Gist options
  • Save andrewtarzia/1335ffcb80a1f7aea1d034194dae30d0 to your computer and use it in GitHub Desktop.
Save andrewtarzia/1335ffcb80a1f7aea1d034194dae30d0 to your computer and use it in GitHub Desktop.
Run PoreMapper on stk molecules
"""
MIT License
Copyright (c) 2023 Andrew Tarzia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import stk
import pore_mapper as pm
bb1 = stk.BuildingBlock(
smiles='NCCN',
functional_groups=[stk.PrimaryAminoFactory()],
)
bb2 = stk.BuildingBlock(
smiles='O=CC(C=O)C=O',
functional_groups=[stk.AldehydeFactory()],
)
cage = stk.ConstructedMolecule(
topology_graph=stk.cage.FourPlusSix(
building_blocks=(bb1, bb2),
optimizer=stk.MCHammer(),
),
)
host = pm.Host(
atoms=(
pm.Atom(id=i.get_id(), element_string=i.__class__.__name__)
for i in cage.get_atoms()
),
position_matrix=cage.get_position_matrix(),
)
# Define calculator object.
calculator = pm.Inflater(bead_sigma=1.0, centroid=host.get_centroid())
# Run calculator on host object, analysing output.
print(f'doing {molfile}')
final_result = calculator.get_inflated_blob(host=host)
pore = final_result.pore
blob = final_result.pore.get_blob()
windows = pore.get_windows()
print(final_result)
print(
f'blob: {blob}\n'
f'pore: {pore}\n'
f'blob_max_diam: {blob.get_maximum_diameter()}\n'
f'pore_max_rad: {pore.get_maximum_distance_to_com()}\n'
f'pore_mean_rad: {pore.get_mean_distance_to_com()}\n'
f'pore_volume: {pore.get_volume()}\n'
f'num_windows: {len(windows)}\n'
f'max_window_size: {max(windows)}\n'
f'min_window_size: {min(windows)}\n'
f'asphericity: {pore.get_asphericity()}\n'
f'shape anisotropy: {pore.get_relative_shape_anisotropy()}\n'
)
print()
# Do final structure.
host.write_xyz_file(xyzfile.replace('.xyz', '_final.xyz'))
blob.write_xyz_file(xyzfile.replace('.xyz', '_blob.xyz'))
pore.write_xyz_file(xyzfile.replace('.xyz', '_pore.xyz'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment