コード例 #1
0
void ReadFileThread::detectConformers(unsigned int c,
                                      const OpenBabel::OBMol &first,
                                      const OpenBabel::OBMol &current)
{
  if (!c) {
    // this is the first molecule read
    m_moleculeFile->setConformerFile(true);
    addConformer(current);
    return;
  }

  if (!m_moleculeFile->isConformerFile())
    return;

  // as long as we are not sure if this really is a
  // conformer/trajectory file, add the conformers
  addConformer(current);

  // performance: check only certain molecule 1-10,20,50
  switch (c) {
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
  case 7:
  case 8:
  case 9:
  case 10:
  case 20:
  case 50:
    break;
  default:
    return;
  }

  if (first.NumAtoms() != current.NumAtoms()) {
    m_moleculeFile->setConformerFile(false);
    m_moleculeFile->m_conformers.clear();
    return;
  }

  for (unsigned int i = 0; i < first.NumAtoms(); ++i) {
    OpenBabel::OBAtom *firstAtom = first.GetAtom(i+1);
    OpenBabel::OBAtom *currentAtom = current.GetAtom(i+1);
    if (firstAtom->GetAtomicNum() != currentAtom->GetAtomicNum()) {
      m_moleculeFile->setConformerFile(false);
      m_moleculeFile->m_conformers.clear();
      return;
    }
  }
}
コード例 #2
0
  // Helper function -- handle SMARTS selections
  // Called by performAction()
  void SelectExtension::selectSMARTS(GLWidget *widget)
  {
    bool ok;
    QString pattern = QInputDialog::getText(qobject_cast<QWidget*>(parent()),
        tr("SMARTS Selection"),
        tr("SMARTS pattern to select"),
        QLineEdit::Normal,
        "", &ok);
    if (ok && !pattern.isEmpty()) {
      OBSmartsPattern smarts;
      smarts.Init(pattern.toStdString());
      OpenBabel::OBMol obmol = m_molecule->OBMol();
      smarts.Match(obmol);

      // if we have matches, select them
      if(smarts.NumMatches() != 0) {
        QList<Primitive *> matchedAtoms;

        vector< vector <int> > mapList = smarts.GetUMapList();
        vector< vector <int> >::iterator i; // a set of matching atoms
        vector<int>::iterator j; // atom ids in each match
        for (i = mapList.begin(); i != mapList.end(); ++i) {
          for (j = i->begin(); j != i->end(); ++j) {
            matchedAtoms.append(m_molecule->atom(obmol.GetAtom(*j)->GetIdx()-1));
          }
        }

        widget->clearSelected();
        widget->setSelected(matchedAtoms, true);
        widget->update();
      } // end matches
    }
    return;
  }
コード例 #3
0
ファイル: molecule.cpp プロジェクト: timvdm/avogadro
void Molecule::addHydrogens(Atom *a,
                            const QList<unsigned long> &atomIds,
                            const QList<unsigned long> &bondIds)
{
    if (atomIds.size() != bondIds.size()) {
        qDebug() << "Error, addHydrogens called with atom & bond id lists of different size!";
    }

    // Construct an OBMol, call AddHydrogens and translate the changes
    OpenBabel::OBMol obmol = OBMol();
    if (a) {
        OpenBabel::OBAtom *obatom = obmol.GetAtom(a->index()+1);
        // Set implicit valence for unusual elements not handled by OpenBabel
        // PR#2803076
        switch (obatom->GetAtomicNum()) {
        case 3:
        case 11:
        case 19:
        case 37:
        case 55:
        case 85:
        case 87:
            obatom->SetImplicitValence(1);
            obatom->SetHyb(1);
            obmol.SetImplicitValencePerceived();
            break;

        case 4:
        case 12:
        case 20:
        case 38:
        case 56:
        case 88:
            obatom->SetImplicitValence(2);
            obatom->SetHyb(2);
            obmol.SetImplicitValencePerceived();
            break;

        case 84: // Po
            obatom->SetImplicitValence(2);
            obatom->SetHyb(3);
            obmol.SetImplicitValencePerceived();
            break;

        default: // do nothing
            break;
        }
        obmol.AddHydrogens(obatom);
    }
    else
        obmol.AddHydrogens();
    // All new atoms in the OBMol must be the additional hydrogens
    unsigned int numberAtoms = numAtoms();
    int j = 0;
    for (unsigned int i = numberAtoms+1; i <= obmol.NumAtoms(); ++i, ++j) {
        if (obmol.GetAtom(i)->IsHydrogen()) {
            OpenBabel::OBAtom *obatom = obmol.GetAtom(i);
            Atom *atom;
            if (atomIds.isEmpty())
                atom = addAtom();
            else if (j < atomIds.size())
                atom = addAtom(atomIds.at(j));
            else {
                qDebug() << "Error - not enough unique ids in addHydrogens.";
                break;
            }
            atom->setOBAtom(obatom);
            // Get the neighbor atom
            OpenBabel::OBBondIterator iter;
            OpenBabel::OBAtom *next = obatom->BeginNbrAtom(iter);
            Bond *bond;
            if (bondIds.isEmpty())
                bond = addBond();
            else // Already confirmed by atom ids
                bond = addBond(bondIds.at(j));
            bond->setEnd(Molecule::atom(atom->index()));
            bond->setBegin(Molecule::atom(next->GetIdx()-1));
        }
    }
    for (unsigned int i = 1; i <= numberAtoms; ++i) {
        // Warning -- OB atom index off-by-one here
        atom(i-1)->setPartialCharge(obmol.GetAtom(i)->GetPartialCharge());
    }
}
コード例 #4
0
	//--
	bool DataProperty::Satisfy(OpenBabel::OBRing* pRing, 
								const std::string& refTo, 
								std::vector<Class*>& vecSatisfiedClasses, 
								std::string& refValue)
	{
		//bool bSatisfied = false;
		int iPosition = -1;

		// [rad] if we are default, we automatically satisfy		
		if(!IsDefault())
		{			
			if(!SatisfyCommon(vecSatisfiedClasses, iPosition))
			{
				// [rad] this property does not apply

				refValue = "";
				return(false);
			}
		}

		// [rad] go through possible data types..

		if(!refTo.compare("RING_SIZE"))
		{
			ConvertInt(pRing->Size(), refValue);
		}
		else if(!refTo.compare("RING_IS_AROMATIC"))
		{
			ConvertBool(pRing->IsAromatic(), refValue);
		}
		else if(!refTo.compare("RING_IS_HOMOCYCLIC"))
		{
			OpenBabel::OBMol* pMolecule = pRing->GetParent();
			OpenBabel::OBAtom* pAtom;

			bool bHomoCyclic = true;

			std::vector<int>::iterator iter_path = pRing->_path.begin();
			while(iter_path != pRing->_path.end())
			{
				pAtom = pMolecule->GetAtom((*iter_path));

				if(pAtom)
				{
					if(6 != pAtom->GetAtomicNum())
					{
						bHomoCyclic = false;
						break;
					}
				}

				iter_path++;
			}

			ConvertBool(bHomoCyclic, refValue);
		}
		else if(!refTo.compare("RING_IS_HETEROCYCLIC"))
		{
			OpenBabel::OBMol* pMolecule = pRing->GetParent();
			OpenBabel::OBAtom* pAtom;

			bool bHeteroCyclic = false;

			std::vector<int>::iterator iter_path = pRing->_path.begin();
			while(iter_path != pRing->_path.end())
			{
				pAtom = pMolecule->GetAtom((*iter_path));

				if(pAtom)
				{
					if(6 != pAtom->GetAtomicNum())
					{
						bHeteroCyclic = true;
						break;
					}
				}

				iter_path++;
			}

			ConvertBool(bHeteroCyclic, refValue);
		}
		else
		{
			// [rad] unknown datatype?
			refValue = "";
			return(false);
		}

		return(true);
	}