<jupyter_start><jupyter_text>Calculating Polymer InteractionsDemo how to calculate inter-chain and intra-chain polymer-polymer interactions. Polymers are chains of proteins, DNA, or RNA.<jupyter_code>from pyspark.sql import SparkSession                  
from mmtfPyspark.io import mmtfReader
from mmtfPyspark.interactions import InteractionExtractor, InteractionFilter<jupyter_output><empty_output><jupyter_text>Configure Spark<jupyter_code>spark = SparkSession.builder.appName("PolymerInteractionsDemo").getOrCreate()<jupyter_output><empty_output><jupyter_text>Download a sample PDB structures<jupyter_code>pdb = mmtfReader.download_mmtf_files(['1OHR', '6CUH'])<jupyter_output><empty_output><jupyter_text>Define Interaction FilterInteraction filters define the criteria for find interactions. Here, we present a couple of simple examples. More advanced options are available.  Define disulfide bond<jupyter_code>disulfide_bond = InteractionFilter(distanceCutoff=3.0)
disulfide_bond.set_query_groups(True, 'CYS')
disulfide_bond.set_query_atom_names(True, 'SG')
disulfide_bond.set_target_groups(True, 'CYS')
disulfide_bond.set_target_atom_names(True, 'SG')<jupyter_output><empty_output><jupyter_text>Define salt bridge interactions<jupyter_code>salt_bridge = InteractionFilter(distanceCutoff=3.5)
salt_bridge.set_query_groups(True, ['ASP', 'GLU'])
salt_bridge.set_query_atom_names(True, ['OD1', 'OD2', 'OE1', 'OE2'])
salt_bridge.set_target_groups(True, ['ARG', 'LYS', 'HIS'])
salt_bridge.set_target_atom_names(True, ['NH1', 'NH2', 'NZ', 'ND1', 'NE2'])<jupyter_output><empty_output><jupyter_text>Find InteractionsUsing the interaction filters defined above we can find these interactions between chains (inter-chain) and within chains (intra-chain).By default, inter-chain interactions are calculated.  Find inter-chain disulfide bondsNote that the queryChainId and targetChainId for each interaction is different.<jupyter_code>interactions = InteractionExtractor.get_polymer_interactions(pdb, disulfide_bond)
interactions.toPandas()<jupyter_output><empty_output><jupyter_text>Find intra-chain disulfide bonds By setting the flags ```intra='True'``` and/or ```inter='True'```, intra-chain, inter-chain, or both can be reported. Here, we calculate the intra-chain disulfide bonds.<jupyter_code>interactions = InteractionExtractor.get_polymer_interactions(pdb, disulfide_bond, inter=False, intra=True)
interactions.toPandas()<jupyter_output><empty_output><jupyter_text>Report interactions at the group and atom levelBy default, interactions are reported at the group (residue) level  Find inter-chain salt bridges at the group level<jupyter_code>interactions = InteractionExtractor.get_polymer_interactions(pdb, salt_bridge)
interactions.toPandas()<jupyter_output><empty_output><jupyter_text>Find inter-chain salt bridges at the atom level By setting the flags ```level='atom'``` or ```level='group'```, interactions can be reported at the atom or group level.At the atom level, the **atom names** and **distances** of the interactions are reported.<jupyter_code>interactions = InteractionExtractor.get_polymer_interactions(pdb, salt_bridge, level='atom')
interactions.toPandas()<jupyter_output><empty_output><jupyter_text>Terminate Spark<jupyter_code>spark.stop()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10118505013673655, 'fraction_numerical': 0.00425402613187481, 'mean_word_length': 9.48407643312102, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '242366', 'license': 'Apache-2.0', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1002, 'n_words': 233, 'path': 'demos/interactions/PolymerInteractionsDemo.ipynb', 'repo_name': 'sbliven/mmtf-pyspark', 'size': '3291'}