<commit_before># -*- coding: utf-8 -*-

"""
file: wamp_services.py

WAMP service methods the module exposes.
"""

import os
import sys
import time

from   autobahn import wamp
from   autobahn.wamp.types import RegisterOptions
from   twisted.internet.defer import inlineCallbacks

from   lie_system  import LieApplicationSession

class StructuresWampApi(LieApplicationSession):

    """
    Structure database WAMP methods.
    """
    
    @inlineCallbacks
    def onJoin(self, details):
        yield self.register(self.get_structure, u'liestudio.structures.get_structure', options=RegisterOptions(invoke=u'roundrobin'))
        self.log.info("DockingWampApi: get_structure() registered!")
    
    def get_structure(self, structure):
        
        result = ''
        currpath = '/Users/mvdijk/Documents/WorkProjects/liestudio-master/liestudio/components/lie_structures-0.1/lie_structures'
        structure_file = os.path.join(currpath, '{0}.mol2'.format(structure))
        if os.path.exists(structure_file):
            with open(structure_file, 'r') as sf:
                result = sf.read()
        
        self.log.info("Return structure: {structure}", structure=structure_file, **self.session_config.dict())
        
        return {'result': result}

def make(config):
    """
    Component factory
  
    This component factory creates instances of the application component
    to run.
    
    The function will get called either during development using an 
    ApplicationRunner, or as a plugin hosted in a WAMPlet container such as
    a Crossbar.io worker.
    The LieApplicationSession class is initiated with an instance of the
    ComponentConfig class by default but any class specific keyword arguments
    can be consument as well to populate the class session_config and<commit_msg>Fixed hardcoded filepath<commit_after># -*- coding: utf-8 -*-

"""
file: wamp_services.py

WAMP service methods the module exposes.
"""

import os
import sys
import time

from   autobahn import wamp
from   autobahn.wamp.types import RegisterOptions
from   twisted.internet.defer import inlineCallbacks

from   lie_system  import LieApplicationSession

class StructuresWampApi(LieApplicationSession):

    """
    Structure database WAMP methods.
    """
    
    @inlineCallbacks
    def onJoin(self, details):
        yield self.register(self.get_structure, u'liestudio.structures.get_structure', options=RegisterOptions(invoke=u'roundrobin'))
        self.log.info("DockingWampApi: get_structure() registered!")
    
    def get_structure(self, structure):
        
        result = ''
        currpath = os.path.dirname(os.path.realpath(__file__))
        structure_file = os.path.join(currpath, '{0}.mol2'.format(structure))
        if os.path.exists(structure_file):
            with open(structure_file, 'r') as sf:
                result = sf.read()
        
        self.log.info("Return structure: {structure}", structure=structure_file, **self.session_config.dict())
        
        return {'result': result}

def make(config):
    """
    Component factory
  
    This component factory creates instances of the application component
    to run.
    
    The function will get called either during development using an 
    ApplicationRunner, or as a plugin hosted in a WAMPlet container such as
    a Crossbar.io worker.
    The LieApplicationSession class is initiated with an instance of the
    ComponentConfig class by default but any class specific keyword arguments
    can be consument as well to populate the class session_config and
{'fraction_non_alphanumeric': 0.08249158249158249, 'fraction_numerical': 0.002244668911335578, 'mean_word_length': 3.259259259259259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '935747', 'n_tokens_mistral': 970, 'n_tokens_neox': 953, 'n_words': 295}