Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'vasp-5.x-from-clipboard'

  • Loading branch information...
commit b68e29262a096ca0296c9185d9a7d7a94ec28981 2 parents 9658f8e + be5356e
@dlonie dlonie authored
View
137 libavogadro/src/extensions/crystallography/crystalpastedialog.cpp
@@ -100,13 +100,10 @@ namespace Avogadro {
{
QStringList lines = text.split("\n");
+ // Title + scale + 3 vectors + composition + direct/cartesian + (no atoms)
if (lines.size() < 7) {
return false;
}
- if (lines.at(7).at(0).toLower() == QChar('s') &&
- lines.size() < 8) {
- return false;
- }
unsigned int lineIndex = 0;
const QString *line;
@@ -142,6 +139,22 @@ namespace Avogadro {
// Next line is a list of unsigned integers (composition)
line = &lines[lineIndex++];
lineList = line->simplified().split(QRegExp("\\s+|,|;"));
+ int numSpecies = lineList.size();
+ if (numSpecies == 0) {
+ return false;
+ }
+ // Check if the first field is an unsigned int (VASP 4.x) or a char (5.x)
+ bool vaspVersionLessThan5;
+ lineList.first().toUInt(&vaspVersionLessThan5);
+ // If vasp >= 5.x, skip the line containing the atomic symbols.
+ if (!vaspVersionLessThan5) {
+ line = &lines[lineIndex++];
+ lineList = line->simplified().split(QRegExp("\\s+|,|;"));
+ if (lineList.size() != numSpecies) {
+ return false;
+ }
+ }
+ // Read in the total number of atoms
for (QStringList::const_iterator
it = lineList.constBegin(),
it_end = lineList.constEnd();
@@ -192,61 +205,79 @@ namespace Avogadro {
void CEPasteDialog::refreshVaspFormat()
{
- QStringList lines = m_text.split("\n");
+ const QStringList lines = m_text.split("\n");
Q_ASSERT(lines.size() >= 7);
Q_ASSERT_X(lines.at(7).at(0).toLower() != QChar('s') ||
lines.size() >= 8, Q_FUNC_INFO,
"'lines' is too short to be a proper POSCAR.");
- // Determine number of atom types
- const QString *typesStr = &lines[5];
- m_numAtomTypes = typesStr->simplified().split(QRegExp("\\s+|,|;")).size();
+ // Count the number of atom types
+ QString line = lines[5];
+ QStringList lineList = line.simplified().split(QRegExp("\\s+|,|;"));
+ m_numAtomTypes = lineList.size();
+ // no atoms?
+ if (m_numAtomTypes == 0) {
+ ui.edit_identities->clear();
+ ui.edit_text->setText(m_text);
+ return;
+ }
+ // Check if the first field is an unsigned int (VASP 4.x) or a char (5.x)
+ bool vaspVersionLessThan5;
+ lineList.first().toUInt(&vaspVersionLessThan5);
- // Try to determine the atom types from the comment line
- const QString *comment = &lines[0];
+ // List of atom identifiers, either atomic numbers or symbols
+ QString idents = "";
- /// @todo Support more style formats
- // Assume alternating numbers / letters for composition, e.g. Sr1Ti3O4, etc.
- // Parse sets of numbers between letters
- QStringList symbolList = comment->split(QRegExp("[0-9|\\s|,|;]+"),
+ // If vasp >= 5.x, just extract the composition that is explicitly
+ // specified
+ if (!vaspVersionLessThan5) {
+ idents = line.simplified();
+ }
+ // For vasp < 5.x, try to guess the composition from the title
+ else {
+ // Try to determine the atom types from the comment line
+ const QString *title = &lines[0];
+
+ // Attempt to parse a set of atomic symbols from the title
+ QStringList symbolList = title->split(QRegExp("[0-9|\\s|,|;]+"),
QString::SkipEmptyParts);
- // Look for the first list of m_numAtomTypes consecutive strings
- // that converts cleanly into atomic numbers:
- QList<unsigned int> atomicNums;
- for (int i = 0; i < symbolList.size(); ++i) {
- atomicNums.append(OpenBabel::etab.GetAtomicNum
- (symbolList.at(i).toStdString().c_str()));
- }
- int startInd = -1;
- for (int i = 0; i < atomicNums.size(); ++i) {
- bool found = true;
- for (unsigned int j = 0; j < m_numAtomTypes; ++j) {
- if (atomicNums.at(i + j) == 0) {
- found = false;
+ // Look for the first list of m_numAtomTypes consecutive strings
+ // that converts cleanly into atomic numbers:
+ QList<unsigned int> atomicNums;
+ for (int i = 0; i < symbolList.size(); ++i) {
+ atomicNums.append(OpenBabel::etab.GetAtomicNum
+ (symbolList.at(i).toStdString().c_str()));
+ }
+ int startInd = -1;
+ for (int i = 0; i < atomicNums.size(); ++i) {
+ bool found = true;
+ for (unsigned int j = 0; j < m_numAtomTypes; ++j) {
+ if (atomicNums.at(i + j) == 0) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ startInd = i;
break;
}
}
- if (found) {
- startInd = i;
- break;
- }
- }
- QString idents = "";
- if (startInd >= 0) {
- // Found list of consecutive identifiers.
- Q_ASSERT(startInd + m_numAtomTypes <=
- static_cast<unsigned int>((symbolList.size())));
- for (unsigned int i = 0; i < m_numAtomTypes; ++i) {
- idents += symbolList.at(startInd + i) + " ";
+ if (startInd >= 0) {
+ // Found list of consecutive identifiers.
+ Q_ASSERT(startInd + m_numAtomTypes <=
+ static_cast<unsigned int>((symbolList.size())));
+ for (unsigned int i = 0; i < m_numAtomTypes; ++i) {
+ idents += symbolList.at(startInd + i) + " ";
+ }
}
- }
- else {
- // Did not find. Fill with consecutive integers.
- for (unsigned int i = 1; i <= m_numAtomTypes; ++i) {
- idents += QString::number(i) + " ";
+ else {
+ // Did not find. Fill with consecutive integers.
+ for (unsigned int i = 1; i <= m_numAtomTypes; ++i) {
+ idents += QString::number(i) + " ";
+ }
}
}
@@ -325,10 +356,20 @@ namespace Avogadro {
// Next line is a list of unsigned integers (composition)
line = &lines[lineIndex++];
lineList = line->simplified().split(QRegExp("\\s+|,|;"));
- for (QStringList::const_iterator
- it = lineList.constBegin(),
- it_end = lineList.constEnd();
- it != it_end; ++it) {
+ // If vasp >= 5.x, this may be a list of atomic symbols. Skip it if so,
+ // since the user should have already specified/verified the composition
+ // in the GUI by this point.
+ if (lineList.isEmpty()) {
+ return false;
+ }
+ bool vaspVersionLessThan5;
+ lineList.first().toUInt(&vaspVersionLessThan5);
+ if (!vaspVersionLessThan5) {
+ line = &lines[lineIndex++];
+ lineList = line->simplified().split(QRegExp("\\s+|,|;"));
+ }
+ for (QStringList::const_iterator it = lineList.constBegin(),
+ it_end = lineList.constEnd(); it != it_end; ++it) {
unsigned int v = it->toUInt(&ok);
if (!ok) {
return false;
View
92 testfiles/VASP-5.2-POSCAR.vasp
@@ -0,0 +1,92 @@
+Example of a VASP 5.2 style POSCAR file.
+1.000
+ 9.789999999999999 0.000000000000000 0.000000000000000
+ 0.000000000000000 3.609000000000000 0.000000000000000
+ -0.550666716486505 0.000000000000001 21.575974025924157
+H C O
+32 28 24
+Cartesian
+ 8.2876719792251254404 3.1470516090000004716 8.9971811688103731086
+ 1.2269946625316199285 1.3425516090000002567 1.7908058441517051840
+ 0.9516613042883674822 0.4619483910000007909 12.5787928571137825884
+ 8.0123386209818736603 2.2664483910000012834 19.7851681817724518453
+ 8.7106006442975587589 0.5124816090000005042 9.6876123376399476683
+ 0.8040659974591882753 2.3169816089999999420 1.1003746753221319565
+ 0.5287326392159358290 3.0965183910000009249 11.8883616882842115814
+ 8.4352672860543052025 1.2920183910000013761 20.4755993506020246286
+ 3.2927107772672070674 1.0754820000000007152 9.8451169480291920166
+ 6.2219558644895389676 2.8799820000000000420 0.9428700649328857208
+ 5.9466225062462871875 2.5335180000000008249 11.7308570778949636804
+ 3.0173774190239548432 0.7290180000000013871 20.6331039609912743060
+ 9.3494566507243170861 2.3422410000000004615 6.9043116882957304981
+ 0.1652099910324290877 0.5377410000000002466 3.8836753246663482386
+ -0.1101233672108234973 1.2667590000000008565 14.6716623376284278635
+ 9.0741232924810635296 3.0712590000000012935 17.6922987012578083466
+ 0.9816413087721529429 0.9383400000000007291 10.6369551947806098013
+ 8.5330253329845948684 2.7428400000000001668 0.1510318181814691019
+ 8.2576919747413413120 2.6706600000000007000 10.9390188311435476720
+ 0.7063079505289003857 0.8661600000000012622 21.4249422077426885380
+ 2.0250659892389144545 2.6273520000000005759 4.6604103895996180640
+ 7.4896006525178320246 0.8228520000000003609 6.1275766233624597845
+ 7.2142672942745793563 0.9816480000000011863 16.9155636363245385212
+ 1.7497326309956622303 2.7861480000000007351 15.4483974025616959125
+ 3.9494753195332372719 1.9777320000000004896 5.9765448051809917374
+ 5.5651913222235087630 0.1732320000000003024 4.8114422077810869993
+ 5.2898579639802560948 1.6312680000000008285 15.5994292207431648478
+ 3.6741419612899846037 3.4357680000000008214 16.7645318181430695859
+ 6.5177626451943151409 0.6496200000000005303 9.2992448051733109793
+ 2.9969039965624308941 2.4541200000000000792 1.4887422077887670913
+ 2.7215706383191786699 2.9593800000000007877 12.2767292207508447177
+ 6.2424292869510624726 1.1548800000000014609 20.0872318181353932687
+ 3.8319635151017625851 1.4760810000000004205 7.8957276947869452499
+ 5.6827031266549834498 3.2805810000000001914 2.8922593181751334868
+ 5.4073697684117307816 2.1329190000000006755 13.6802463311372122234
+ 3.5566301568585099169 0.3284190000000011822 18.6837147077490257630
+ 2.9653886326072838031 1.3183713090000006574 8.9760367142649677419
+ 6.5492780091494626760 3.1228713089999997621 1.8119502986971107727
+ 6.2739446509062100077 2.2906286910000011048 12.5999373116591915078
+ 2.6900552743640311348 0.4861286910000012784 19.7640237272270447022
+ 1.1455211025595690710 1.9517508090000004195 7.5531012272552695563
+ 8.3691455391971771860 0.1472508090000001768 3.2348857857068091803
+ 8.0938121809539254059 1.6572491910000008986 14.0228727986688870288
+ 0.8701877443163166248 3.4617491910000013355 18.3410882402173491812
+ 1.6200778597019032112 1.5612497910000004975 8.7906990973822800584
+ 7.8945887820548437119 3.3657497909999998242 1.9972879155797993445
+ 7.6192554238115910437 2.0477502090000010426 12.7852749285418791914
+ 1.3447445014586505430 0.2432502090000012163 19.5786861103443570187
+ 2.0110564117152347485 2.0867201910000003906 6.4751655649200987597
+ 7.5036102300415112865 0.2822201910000002867 4.3128214480419799770
+ 7.2282768717982586182 1.5222798090000007054 15.1008084610040587137
+ 1.7357230534719820803 3.3267798090000009203 17.2631525778821774963
+ 3.3566645446475185111 1.8517815090000004918 6.6488521558287878577
+ 6.1580020971092288562 0.0472815090000002561 4.1391348571332908790
+ 5.8826687388659761879 1.7572184910000010483 14.9271218700953696157
+ 3.0813311864042662869 3.5617184910000005971 17.4368391687908683707
+ 5.2974954580788846670 1.2252518910000003149 8.0499959090723027799
+ 4.2171711836778618121 3.0297518910000000858 2.7379911038897759568
+ 3.9418378254346091438 2.3837481090000007811 13.5259781168518546934
+ 5.0221620998356319987 0.5792481090000012323 18.8379829220343815166
+ 1.4266522277996198653 2.4205599090000005091 5.2837402792085672587
+ 8.0880144139571257256 0.6160599090000002942 5.5042467337535114780
+ 7.8126810557138739455 1.1884400910000010310 16.2922337467155884383
+ 1.1513188695563671970 2.9929400910000008018 16.0717272921706459954
+ 5.6181686453811394699 0.7387586910000005780 9.2183349025760961126
+ 3.8964979963756065651 2.5432586909999996827 1.5696521103859824020
+ 3.6211646381323543409 2.8702413090000011842 12.3576391233480613607
+ 5.3428352871378876898 1.0657413090000011913 20.0063219155381766257
+ 6.1032495434518416744 1.4472090000000004117 7.1666755324509683334
+ 3.4114170983049043606 3.2517090000000004046 3.6213114805111104033
+ 3.1360837400616521364 2.1617910000000009063 14.4092984934731891400
+ 5.8279161852085898943 0.3572910000000011355 17.9546625454130470700
+ 8.1362431381908670858 3.5667710910000005597 9.4450983895885585184
+ 1.3784235035658800594 1.7622710909999999007 1.3428886233735195521
+ 1.1030901453226276132 0.0422289090000007583 12.1308756363355971786
+ 7.8609097799476144175 1.8467289090000011953 20.2330854025506390315
+ 0.7080528440135860357 1.4461299090000006018 9.8105953895877142656
+ 8.8066137977431591111 3.2506299089999997065 0.9773916233743643600
+ 8.5312804394999073310 2.1628700910000011604 11.7653786363364432077
+ 0.4327194857703334785 0.3583700910000012785 20.5985824025497912260
+ 9.5934973828420471165 2.2061817000000001343 7.4307654545282790792
+ -0.0788307410853001655 0.4016817000000001969 3.3572215584337987693
+ -0.3541640993285526395 1.4028183000000007397 14.1452085713958766178
+ 9.3181640245987953364 3.2073183000000016207 18.2187524674903578159
Please sign in to comment.
Something went wrong with that request. Please try again.