Esempio n. 1
0
void MangoIndex::prepare (Scanner &molfile, Output &output, 
                          OsLock *lock_for_exclusive_access)
{
   QS_DEF(Molecule, mol);

   QS_DEF(Array<int>, gross);

   MoleculeAutoLoader loader(molfile);

   loader.treat_x_as_pseudoatom = _context->treat_x_as_pseudoatom;
   loader.ignore_closing_bond_direction_mismatch =
           _context->ignore_closing_bond_direction_mismatch;
   loader.loadMolecule(mol);

   //Skip all SGroups
   mol.clearSGroups();

   Molecule::checkForConsistency(mol);

   // Make aromatic molecule
   MoleculeAromatizer::aromatizeBonds(mol, AromaticityOptions::BASIC);

   MangoExact::calculateHash(mol, _hash);

   if (!skip_calculate_fp)
   {
      MoleculeFingerprintBuilder builder(mol, _context->fp_parameters);
      profTimerStart(tfing, "moleculeIndex.createFingerprint");
      builder.process();
      profTimerStop(tfing);

      _fp.copy(builder.get(), _context->fp_parameters.fingerprintSize());
      _fp_sim_bits_count = builder.countBits_Sim();
      output.writeBinaryWord((word)_fp_sim_bits_count);

      const byte *fp_sim_ptr = builder.getSim();
      int fp_sim_size = _context->fp_parameters.fingerprintSizeSim();

      ArrayOutput fp_sim_output(_fp_sim_str);

      for (int i = 0; i < fp_sim_size; i++)
         fp_sim_output.printf("%02X", fp_sim_ptr[i]);

      fp_sim_output.writeChar(0);
   }

   ArrayOutput output_cmf(_cmf);
   {
      // CmfSaver modifies _context->cmf_dict and 
      // requires exclusive access for this
      OsLockerNullable locker(lock_for_exclusive_access);

      CmfSaver saver(_context->cmf_dict, output_cmf);

      saver.saveMolecule(mol);
      
      if (mol.have_xyz)
      {
         ArrayOutput output_xyz(_xyz);
         saver.saveXyz(output_xyz);
      }
      else
         _xyz.clear();
   }

   output.writeArray(_cmf);

   // Save gross formula
   GrossFormula::collect(mol, gross);
   GrossFormula::toString(gross, _gross_str);

   _counted_elems_str.clear();
   _counted_elem_counters.clear();

   ArrayOutput ce_output(_counted_elems_str);

   for (int i = 0; i < (int)NELEM(counted_elements); i++)
   {
      _counted_elem_counters.push(gross[counted_elements[i]]);
      ce_output.printf(", %d", gross[counted_elements[i]]);
   }

   ce_output.writeByte(0);

   // Calculate molecular mass
   MoleculeMass mass_calulator;
   mass_calulator.relative_atomic_mass_map = &_context->relative_atomic_mass_map;
   _molecular_mass = mass_calulator.molecularWeight(mol);
}
Esempio n. 2
0
void MangoIndex::prepare (Scanner &molfile, Output &output,
                          OsLock *lock_for_exclusive_access)
{
    QS_DEF(Molecule, mol);

    QS_DEF(Array<int>, gross);

    MoleculeAutoLoader loader(molfile);
    _context->setLoaderSettings(loader);
    loader.loadMolecule(mol);

    // Skip all SGroups
    mol.clearSGroups();

    if (_context->allow_non_unique_dearomatization)
        MoleculeDearomatizer::restoreHydrogens(mol, false);

    if (_context->zero_unknown_aromatic_hydrogens)
    {
        mol.restoreAromaticHydrogens();
        for (int i : mol.vertices())
        {
            if (mol.isRSite(i) || mol.isPseudoAtom(i))
                continue;

            if (mol.getAtomAromaticity(i) == ATOM_AROMATIC && mol.getImplicitH_NoThrow(i, -1) == -1)
                mol.setImplicitH(i, 0);
        }
    }

    Molecule::checkForConsistency(mol);

    // Make aromatic molecule
    MoleculeAromatizer::aromatizeBonds(mol, AromaticityOptions::BASIC);

    MangoExact::calculateHash(mol, _hash);

    if (!skip_calculate_fp)
    {
        MoleculeFingerprintBuilder builder(mol, _context->fp_parameters);
        profTimerStart(tfing, "moleculeIndex.createFingerprint");
        builder.process();
        profTimerStop(tfing);

        _fp.copy(builder.get(), _context->fp_parameters.fingerprintSize());
        _fp_sim_bits_count = builder.countBits_Sim();
        output.writeBinaryWord((word)_fp_sim_bits_count);

        const byte *fp_sim_ptr = builder.getSim();
        int fp_sim_size = _context->fp_parameters.fingerprintSizeSim();

        ArrayOutput fp_sim_output(_fp_sim_str);

        for (int i = 0; i < fp_sim_size; i++)
            fp_sim_output.printf("%02X", fp_sim_ptr[i]);

        fp_sim_output.writeChar(0);
    }

    ArrayOutput output_cmf(_cmf);
    {
        // CmfSaver modifies _context->cmf_dict and
        // requires exclusive access for this
        OsLockerNullable locker(lock_for_exclusive_access);

        CmfSaver saver(_context->cmf_dict, output_cmf);

        saver.saveMolecule(mol);

        if (mol.have_xyz)
        {
            ArrayOutput output_xyz(_xyz);
            saver.saveXyz(output_xyz);
        }
        else
            _xyz.clear();
    }

    output.writeArray(_cmf);

    // Save gross formula
    GrossFormula::collect(mol, gross);
    GrossFormula::toString(gross, _gross_str);

    _counted_elems_str.clear();
    _counted_elem_counters.clear();

    ArrayOutput ce_output(_counted_elems_str);

    for (int i = 0; i < (int)NELEM(counted_elements); i++)
    {
        _counted_elem_counters.push(gross[counted_elements[i]]);
        ce_output.printf(", %d", gross[counted_elements[i]]);
    }

    ce_output.writeByte(0);

    // Calculate molecular mass
    MoleculeMass mass_calulator;
    mass_calulator.relative_atomic_mass_map = &_context->relative_atomic_mass_map;
    _molecular_mass = mass_calulator.molecularWeight(mol);
}