Changeset bea169516b1c2a35f2b8a030fa4d731c09e954ec

Show
Ignore:
Timestamp:
04/20/12 11:08:47 (13 months ago)
Author:
David C. Lonie <loniedavid@…>
Children:
a426e387c8cde074662fe6aa3a60c39141e5390b
Parents:
2725e2b7f3f9c7aca8436e7efe8b4075e097f4ba
git-author:
David C. Lonie <loniedavid@…> (10/27/11 13:29:25)
git-committer:
David C. Lonie <loniedavid@…> (04/20/12 11:08:47)
Message:

Added XtalOpt::replaceWithOffspring[M]Xtal()

Location:
src/xtalopt
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/xtalopt/xtalopt.cpp

    r2725e2b7 rbea16951  
    471471                                           const QString & reason) 
    472472  { 
     473    if (this->isMolecularXtalSearch()) { 
     474      MolecularXtal *mxtal =  qobject_cast<MolecularXtal*>(s); 
     475      return static_cast<Structure*>( 
     476            this->replaceWithOffspringMXtal(mxtal, reason)); 
     477    } 
     478    else { 
     479      Xtal *xtal =  qobject_cast<Xtal*>(s); 
     480      return static_cast<Structure*>( 
     481            this->replaceWithOffspringXtal(xtal, reason)); 
     482    } 
     483    // Shouldn't happen, but some compilers aren't that bright... 
     484    return NULL; 
     485  } 
     486 
     487  Xtal* XtalOpt::replaceWithOffspringXtal(Xtal *oldXtal, const QString &reason) 
     488  { 
    473489    // Generate/Check new xtal 
    474490    Xtal *xtal = 0; 
     
    481497    } 
    482498 
    483     Xtal *oldXtal = qobject_cast<Xtal*>(s); 
    484499    // Copy info over 
    485500    QWriteLocker locker1 (oldXtal->lock()); 
     
    508523    // Delete random xtal 
    509524    xtal->deleteLater(); 
    510     return static_cast<Structure*>(oldXtal); 
     525    return oldXtal; 
     526  } 
     527 
     528  MolecularXtal* XtalOpt::replaceWithOffspringMXtal( 
     529      MolecularXtal *oldMXtal, const QString &reason) 
     530  { 
     531    // Generate/Check new mxtal 
     532    MolecularXtal *mxtal = NULL; 
     533    while (!checkXtal(mxtal)) { 
     534      if (mxtal) { 
     535        mxtal->deleteLater(); 
     536        mxtal = NULL; 
     537      } 
     538      mxtal = generateNewMXtal(); 
     539    } 
     540 
     541    // Copy info over 
     542    QWriteLocker locker (oldMXtal->lock()); 
     543    QWriteLocker locker2 (mxtal->lock()); 
     544    //! @todo Verify that this assignment doesn't do anything unusual. 
     545    oldMXtal->copyStructure(*mxtal); 
     546    oldMXtal->resetEnergy(); 
     547    oldMXtal->resetEnthalpy(); 
     548    oldMXtal->setPV(0); 
     549    oldMXtal->setCurrentOptStep(1); 
     550    QString parents = mxtal->getParents(); 
     551    if (!reason.isEmpty()) 
     552      parents += " (" + reason + ")"; 
     553    oldMXtal->setParents(parents); 
     554    oldMXtal->findSpaceGroup(tol_spg); 
     555    oldMXtal->resetFailCount(); 
     556 
     557    // Flag for preoptimization 
     558    if (this->usePreopt) { 
     559      oldMXtal->setNeedsPreoptimization(true); 
     560    } 
     561 
     562    // Delete offspring mxtal 
     563    mxtal->deleteLater(); 
     564    return oldMXtal; 
    511565  } 
    512566 
  • src/xtalopt/xtalopt.h

    r2725e2b7 rbea16951  
    9999    GlobalSearch::Structure* replaceWithOffspring(GlobalSearch::Structure *s, 
    100100                                                  const QString &reason = ""); 
     101    Xtal* replaceWithOffspringXtal(Xtal *s, 
     102                                   const QString &reason = ""); 
     103    MolecularXtal* replaceWithOffspringMXtal(MolecularXtal *s, 
     104                                             const QString &reason = ""); 
     105 
    101106    bool checkLimits(); 
    102107    bool checkXtal(Xtal *xtal, QString * err = NULL);