passing all tests

This commit is contained in:
Greg Landrum
2013-11-12 07:21:34 +01:00
parent deabce8146
commit cc4a8e12ea
5 changed files with 73 additions and 17 deletions

View File

@@ -546,13 +546,14 @@ namespace {
nelec--;
}
}
if (nelec%2 == 1) {
if (nelec%2 == 1 || at->getNumRadicalElectrons()==1) {
res = OneElectronDonorType;
}
else {
res = TwoElectronDonorType;
}
}
//std::cerr<<" "<<at->getIdx()<<" "<<at->getAtomicNum()<<" "<<res<<std::endl;;
return(res);
}
}// end of local utility namespace

View File

@@ -208,7 +208,7 @@ int Atom::calcExplicitValence(bool strict) {
// check accum is greater than the default valence
int chr = getFormalCharge();
if(d_atomicNum>1){
unsigned int dv = PeriodicTable::getTable()->getDefaultValence(d_atomicNum-chr);
int dv = PeriodicTable::getTable()->getDefaultValence(d_atomicNum-chr);
if (accum > dv && this->getIsAromatic()){
// this needs some explanation : if the atom is aromatic and
// accum > (dv + chr) we assume that no hydrogen can be added
@@ -398,14 +398,19 @@ int Atom::calcImplicitValence(bool strict) {
else {
// non-aromatic case we are allowed to have non default valences
// and be able to add hydrogens
res = -1;
const INT_VECT &valens = PeriodicTable::getTable()->getValenceList(d_atomicNum-chg);
for (INT_VECT_CI vi = valens.begin();
vi != valens.end() && *vi>=0; ++vi) {
int tot = (*vi);
if (explicitPlusRadV <= tot) {
res = tot - explicitPlusRadV;
break;
if(valens.size()==1 && valens[0]==-1){
// no default valence, set res to zero
res = 0;
} else {
res = -1;
for (INT_VECT_CI vi = valens.begin();
vi != valens.end() && *vi>=0; ++vi) {
int tot = (*vi);
if (explicitPlusRadV <= tot) {
res = tot - explicitPlusRadV;
break;
}
}
}
if (res < 0) {
@@ -415,7 +420,7 @@ int Atom::calcImplicitValence(bool strict) {
std::ostringstream errout;
errout << "Explicit valence for atom # " << getIdx()
<< " " << PeriodicTable::getTable()->getElementSymbol(d_atomicNum)
<< " greater than permitted";
<< ", " << res <<", greater than permitted";
std::string msg = errout.str();
BOOST_LOG(rdErrorLog) << msg << std::endl;
throw MolSanitizeException(msg);

View File

@@ -2546,7 +2546,7 @@ void testAromaticityEdges()
RWMol *m;
std::string smi;
#if 1
// ------
// this was sf.net bug 1934360
smi = "C1=C=NC=N1";
@@ -2652,6 +2652,25 @@ void testAromaticityEdges()
TEST_ASSERT(m->getAtomWithIdx(1)->getIsAromatic());
TEST_ASSERT(m->getBondBetweenAtoms(1,2)->getIsAromatic());
delete m;
#endif
// ------
// Caused problems from InChI
smi = "C[N]C1=CC=NC=C1";
m = SmilesToMol(smi);
TEST_ASSERT(m);
TEST_ASSERT(m->getNumAtoms()==8);
TEST_ASSERT(m->getAtomWithIdx(5)->getNumRadicalElectrons()==0);
TEST_ASSERT(m->getAtomWithIdx(5)->getIsAromatic());
delete m;
smi = "CN=C1C=C[N]C=C1";
m = SmilesToMol(smi);
TEST_ASSERT(m);
TEST_ASSERT(m->getNumAtoms()==8);
TEST_ASSERT(m->getAtomWithIdx(5)->getNumRadicalElectrons()==1);
TEST_ASSERT(!m->getAtomWithIdx(5)->getIsAromatic());
delete m;
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
@@ -4468,7 +4487,6 @@ int main(){
testSFNetIssue3185548();
testSFNetIssue3349243();
testFastFindRings();
#endif
testSanitizeNonringAromatics();
testAtomAtomMatch();
testSFNetIssue3349243();
@@ -4483,12 +4501,12 @@ int main(){
testGitHubIssue42();
testGitHubIssue65();
testSFNetIssue2952255();
testAromaticityEdges();
#endif
testBareHs();
testGitHubIssue72();
testRenumberAtoms();
testGithubIssue141();
#endif
testAromaticityEdges();
return 0;
}

View File

@@ -226,16 +226,48 @@ void testGithubIssue68(){
BOOST_LOG(rdInfoLog) <<"done" << std::endl;
}
void testMiscValenceProblems(){
BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl;
BOOST_LOG(rdInfoLog) <<"testing miscellaneous valence problems" << std::endl;
{
ExtraInchiReturnValues tmp;
std::string inchi="InChI=1S/Ga/q+3";
ROMol *m = InchiToMol(inchi,tmp);
TEST_ASSERT(m);
TEST_ASSERT(m->getNumAtoms()==1);
TEST_ASSERT(m->getAtomWithIdx(0)->getFormalCharge()==3);
delete m;
}
{
ExtraInchiReturnValues tmp;
std::string inchi="InChI=1S/C6H7N2/c1-7-6-2-4-8-5-3-6/h2-5H,1H3";
ROMol *m = InchiToMol(inchi,tmp);
TEST_ASSERT(m);
TEST_ASSERT(m->getNumAtoms()==8);
TEST_ASSERT(m->getAtomWithIdx(7)->getNumRadicalElectrons()==1);
TEST_ASSERT(!m->getAtomWithIdx(7)->getIsAromatic());
delete m;
}
BOOST_LOG(rdInfoLog) <<"done" << std::endl;
}
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int main(){
RDLog::InitLogs();
#if 1
testMultiThread();
testGithubIssue3();
testGithubIssue8();
testGithubIssue40();
testGithubIssue67();
testGithubIssue68();
#endif
testMiscValenceProblems();
}

View File

@@ -224,7 +224,7 @@ class TestCase(unittest.TestCase):
)
)
except:
print '>>> mol failed:',midx,MolToSmiles(m,True),x
print '>>> mol(%d), cid(%s) failed:'%(midx,cid),MolToSmiles(m,True),x
y = ''
if y == '':
# metal involved?
@@ -295,8 +295,8 @@ class TestCase(unittest.TestCase):
same += 1
print green + "InChI Read Summary: %d identical, %d variance, %d reasonable variance" % (same, diff, reasonable) + reset
self.assertEqual(same, 544)
self.assertEqual(diff, 1)
self.assertEqual(reasonable, 636)
self.assertEqual(diff, 0)
self.assertEqual(reasonable, 637)
def test2InchiOptions(self):
m = MolFromSmiles("CC=C(N)C")