Skip to content

Commit bb9ff2d

Browse files
committed
Merge branch 'upstream-objcryst'
* Raise invalid_argument when InitSpaceGroup fails * skip exception in CIF reader when testing SpaceGroup origins * Fix infinite recursion in SpaceGroup("bad") * Fix misleading debug message
2 parents 33d0568 + 5ae1776 commit bb9ff2d

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/ObjCryst/ObjCryst/CIF.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,15 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX
11201120
unsigned int bestscore=0;
11211121
for(vector<string>::const_iterator posOrig=origin_list.begin();posOrig!=origin_list.end();++posOrig)
11221122
{
1123-
// The origin extension may not make sense, but this will be handled internally in SpaceGroup
1124-
pCryst->GetSpaceGroup().ChangeSpaceGroup(hmorig+*posOrig);
1123+
// The origin extension may not make sense, so we need to watch for exception
1124+
try
1125+
{
1126+
pCryst->GetSpaceGroup().ChangeSpaceGroup(hmorig+*posOrig);
1127+
}
1128+
catch(invalid_argument)
1129+
{
1130+
continue;
1131+
}
11251132

11261133
// If the symbol is the same as before, the origin probably was not understood - no need to test
11271134
if((posOrig!=origin_list.begin())&&(pCryst->GetSpaceGroup().GetName()==bestsymbol)) continue;

src/ObjCryst/ObjCryst/Molecule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7677,7 +7677,7 @@ vector<MolAtom*>::reverse_iterator Molecule::FindAtom(const string &name)
76777677
for(rpos=mvpAtom.rbegin();rpos!=mvpAtom.rend();++rpos)
76787678
if(name==(*rpos)->GetName())
76797679
{
7680-
VFN_DEBUG_EXIT("Molecule::FindAtom():"<<name<<"...NOT FOUND !",4)
7680+
VFN_DEBUG_EXIT("Molecule::FindAtom():"<<name<<"...FOUND !",4)
76817681
return rpos;
76827682
}
76837683
VFN_DEBUG_EXIT("Molecule::FindAtom():"<<name<<"...NOT FOUND !",4)

src/ObjCryst/ObjCryst/SpaceGroup.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -581,27 +581,29 @@ void SpaceGroup::InitSpaceGroup(const string &spgId)
581581
#endif
582582
try
583583
{
584+
// replace mpCCTbxSpaceGroup only after we get new space group
584585
cctbx::sgtbx::space_group_symbols sgs=cctbx::sgtbx::space_group_symbols(spgId);
585-
if(mpCCTbxSpaceGroup!=0) delete mpCCTbxSpaceGroup;
586-
mpCCTbxSpaceGroup=0;
587-
mpCCTbxSpaceGroup = new cctbx::sgtbx::space_group(sgs);
586+
cctbx::sgtbx::space_group *nsg = new cctbx::sgtbx::space_group(sgs);
587+
assert(nsg);
588+
delete mpCCTbxSpaceGroup;
589+
mpCCTbxSpaceGroup = nsg;
588590
}
589-
catch(exception &ex1)
591+
catch(cctbx::error ex1)
590592
{
591593
try
592594
{
593-
(*fpObjCrystInformUser)("Failed lookup symbol ! try Hall symbol ?");
594-
if(mpCCTbxSpaceGroup!=0) delete mpCCTbxSpaceGroup;
595-
mpCCTbxSpaceGroup=0;
596-
mpCCTbxSpaceGroup = new cctbx::sgtbx::space_group(spgId);
595+
(*fpObjCrystInformUser)("Lookup of '" + spgId + "' symbol failed, trying as Hall symbol.");
596+
// replace mpCCTbxSpaceGroup only after we get new space group
597+
cctbx::sgtbx::space_group *nsg = new cctbx::sgtbx::space_group(spgId);
598+
assert(nsg);
599+
delete mpCCTbxSpaceGroup;
600+
mpCCTbxSpaceGroup = nsg;
597601
}
598-
catch(exception &ex2)
602+
catch(cctbx::error ex2)
599603
{
600604
(*fpObjCrystInformUser)("Could not interpret Spacegroup Symbol:"+spgId);
601-
(*fpObjCrystInformUser)("Reverting to spacegroup symbol:"+mId);
602-
this->InitSpaceGroup(mId);
603-
VFN_DEBUG_EXIT("SpaceGroup::InitSpaceGroup() could not interpret spacegroup:"<<spgId<<":"<<ex1.what()<<":"<<ex2.what(),8)
604-
return;
605+
string emsg = "Space group symbol '" + spgId + "' not recognized";
606+
throw invalid_argument(emsg);
605607
}
606608
}
607609

@@ -642,13 +644,17 @@ void SpaceGroup::InitSpaceGroup(const string &spgId)
642644

643645
mExtension='\0'; //this->GetCCTbxSpg().type().extension();
644646
}
645-
catch(exception &ex)
647+
catch(cctbx::error ex)
646648
{
647649
(*fpObjCrystInformUser)("Error initializing spacegroup (Incorrect Hall symbol ?):"+spgId);
648-
this->InitSpaceGroup(mId);
649-
(*fpObjCrystInformUser)("Reverting to spacegroup symbol:"+mId);
650+
if (mId != spgId)
651+
{
652+
(*fpObjCrystInformUser)("Reverting to spacegroup symbol:"+mId);
653+
this->InitSpaceGroup(mId);
654+
}
650655
VFN_DEBUG_EXIT("SpaceGroup::InitSpaceGroup() could not interpret spacegroup:"<<spgId<<":"<<ex.what(),8)
651-
return;
656+
string emsg = "Space group symbol '" + spgId + "' not recognized";
657+
throw invalid_argument(emsg);
652658
}
653659

654660
mExtension=this->GetCCTbxSpg().match_tabulated_settings().extension();

0 commit comments

Comments
 (0)