Skip to content

Commit

Permalink
Retrieve an ion by string containing both symbol & charge.
Browse files Browse the repository at this point in the history
Refs #7020
  • Loading branch information
martyngigg committed Jun 3, 2013
1 parent 4013445 commit 030fd30
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/MagneticIon.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace PhysicalConstants

/// Returns the magnetic ion for the given symbol and charge
MANTID_KERNEL_DLL const MagneticIon & getMagneticIon(const std::string &symbol,const uint16_t charge);
/// Returns the magnetic ion from a combined symbol and charge given as string
MANTID_KERNEL_DLL const MagneticIon & getMagneticIon(const std::string &symbol);
/// Returns the Lth-coefficients for the given ion
MANTID_KERNEL_DLL std::vector <double> getJL(const std::string &symbol,const uint16_t charge, const uint16_t l = 0);

Expand Down
29 changes: 20 additions & 9 deletions Code/Mantid/Framework/Kernel/src/MagneticIon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,30 +679,41 @@ namespace Mantid
}

/**
* Returns a MagneticIon corresponding to the given symbol & charge.
* Returns a MagneticIon corresponding to the given symbol containing the atom & charge
* Throws std::runtime_error if one cannot be found
* @param symbol :: The string symbol
* @param charge :: The charge
* @return
* @return A reference to the required ion
*/
const MagneticIon & getMagneticIon(const std::string & symbol,const uint16_t charge)
const MagneticIon & getMagneticIon(const std::string & symbol)
{
const IonIndex & ionIndex = ionMap();
std::stringstream what;
what << symbol << charge;
std::map<std::string, MagneticIon>::const_iterator cit = ionIndex.find(what.str());
std::map<std::string, MagneticIon>::const_iterator cit = ionIndex.find(symbol);

if (cit == ionIndex.end())
{
//no such combination
std::stringstream msg;
msg << "Failed to find an atom with symbol=" << symbol << " and charge=" << charge;
msg << "Failed to find an atom using symbol=" << symbol;
throw std::runtime_error(msg.str());
}
else
{
return cit->second;
}
}
}

/**
* Returns a MagneticIon corresponding to the given symbol & charge.
* Throws std::runtime_error if one cannot be found
* @param symbol :: The string symbol
* @param charge :: The charge
* @return
*/
const MagneticIon & getMagneticIon(const std::string & symbol,const uint16_t charge)
{
std::stringstream what;
what << symbol << charge;
return getMagneticIon(what.str());
}

/**
Expand Down
13 changes: 10 additions & 3 deletions Code/Mantid/Framework/Kernel/test/MagneticIonTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ using namespace Mantid::PhysicalConstants;
class MagneticIonTest : public CxxTest::TestSuite
{
public:
void testGetMagneticIon()
void testGetMagneticIonWithSeparateSymbolAndCharge()
{
MagneticIon temp;
temp=getMagneticIon("Am",7);
MagneticIon temp=getMagneticIon("Am",7);
TS_ASSERT_EQUALS(temp.symbol,"Am");
TS_ASSERT_EQUALS(temp.charge,7);
TS_ASSERT_DELTA(temp.j0[1],12.73,0.001);
}

void testGetMagneticIonWithCombinedSymbolAndCharge()
{
MagneticIon temp=getMagneticIon("Am7");
TS_ASSERT_EQUALS(temp.symbol,"Am");
TS_ASSERT_EQUALS(temp.charge,7);
TS_ASSERT_DELTA(temp.j0[1],12.73,0.001);
}

void testGetJL()
{
std::vector <double> temp;
Expand Down

0 comments on commit 030fd30

Please sign in to comment.