示例#1
0
 def _tautomerize(self, reaction: ReactionContainer) -> ReactionContainer:
     """
     Perform ChemAxon tautomerization.
     :param reaction: reaction that needs to be tautomerized
     :return: ReactionContainer
     """
     new_molecules = []
     for part in [reaction.reactants, reaction.reagents, reaction.products]:
         tmp = []
         for mol in part:
             with io.StringIO() as f, SDFWrite(f) as i:
                 i.write(mol)
                 sdf = f.getvalue()
             mol_handler = self._MolHandler(sdf)
             mol_handler.clean(True, '2')
             molecule = mol_handler.getMolecule()
             self._standardizer.standardize(molecule)
             new_mol_handler = self._MolHandler(molecule)
             new_sdf = new_mol_handler.toFormat('SDF')
             with io.StringIO('\n  ' + new_sdf.strip()) as f, SDFRead(f, remap=False) as i:
                 new_mol = next(i)
             tmp.append(new_mol)
         new_molecules.append(tmp)
     return ReactionContainer(reactants=tuple(new_molecules[0]), reagents=tuple(new_molecules[1]),
                              products=tuple(new_molecules[2]), meta=reaction.meta)
示例#2
0
from RNNSynthesis.helper import get_feature, get_feature_bits
logger = logging.getLogger("exampleApp")
logger.setLevel(logging.INFO)

# create the logging file handler
fh = logging.FileHandler("GA.log")

formatter = logging.Formatter()
fh.setFormatter(formatter)

# add handler to logger object
logger.addHandler(fh)

logger.info("Program started")

target = next(SDFRead(open('./data/tylenol.sdf', encoding='UTF-8')))
env = SimpleSynthesis(target, steps=10)
target_bits = get_feature_bits(target)
step_per_score = dict()


def fit_func(hromosoma):
    for action in hromosoma:
        state, reward, done, info = env.step(action)
        if done:
            if state == target_bits:
                logger.info(
                    f'синтетический путь для молекулы {target} = {[step for step in env.render()]}'
                )
                print(
                    f'синтетический путь для молекулы {target} = {[step for step in env.render()]}'
示例#3
0
import os
os.environ['DB'] = '/home/ilnur/PycharmProjects/RLFS/data/db.shelve'
os.environ['DATA'] = '/home/ilnur/PycharmProjects/RLFS/data/rules/'

from RNNSynthesis.environment import SimpleSynthesis
from CGRtools.files import SDFRead


target = next(SDFRead(open('/home/ilnur/PycharmProjects/RLFS/data/tylenol.sdf', encoding='UTF-8')))
env = SimpleSynthesis(target, steps=1000, reward_at_end=True)


示例#4
0
#         self.af = activation
#         self.
#
#     def forward(self, mc, state, action_space): #шаг вперед
#         fp = get_feature_bits(mc)
#
#
#     def loss(self): #на основании награды считать лосс функцию
#         ...

# mine | gym:
# state = observation_space
# action_space = action_space
# reward = reward

with SDFRead('/home/ilnur/Загрузки/molSet_largestCluster.sdf', 'rb') as f:
    mc = next(f)

device = device("cuda" if cuda.is_available() else "cpu")
lr = 0.0001
env = SimpleSynthesis(mc)


class Actor(Module):
    def __init__(self, action_size, inp_size=8192, learning_rate=0.0001):  # state == molecule_container
        super(Actor, self).__init__()
        self.inps = inp_size
        self.ac = action_size
        self.lr = learning_rate
        self.linear1 = Linear(self.inps, 128)
        self.linear2 = Linear(128, 256)