'How to use a Python class file in another script (in Matlab)
I am new to python and mainly use Matlab. I found some Python code on Github (https://github.com/simonmb/fragmentation_algorithm) that I want to run in Matlab, but I can't even manage to write a function in Python to run the code with any input. When I try to run the function I wrote (called 'RunFrag.py') in the Console in PyCharm, I only get the following error: NameError: name 'RunFrag' is not defined, even though the script is in the same folder. The file from Github ('fragmenter.py') defines a class and has the line __name__ == '__main__' and I have no idea how to deal with this, in Matlab classes occur rather rarely.
Can anyone help me with creating a function where I can just enter a SMILES molecule as input and get the fragmentation out? Thanks in advance.
Here is the Code from the RunFrag function I wrote (the additionally needed fragmenter.py file can be found at the github link):
def RunFrag(smiles):
from .fragmenter import fragmenter
fragmentation_scheme = {
'CH2' : '[CH2]',
'OH' : '[OH]',
'CH3' : '[CH3]',
'CH2-CH2' : '[CH2][CH2]'
}
fragmentation_scheme_order1 = ['CH2-CH2', 'CH3', 'CH2', 'OH']
frg = fragmenter(fragmentation_scheme, fragmentation_scheme_order=fragmentation_scheme_order1, algorithm='simple')
fragmentation, success, fragmentation_matches = frg.fragment(smiles)
return smiles, fragmentation, success
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
