Commit fe1d6044 authored by Adam Fekete's avatar Adam Fekete
Browse files

init

parent d1869a54
This source diff could not be displayed because it is too large. You can view the blob instead.
# analytics-compressed-sensing-2018
# CompressedSensing4MaterialsScience
A machine-learning tutorial on how to identify materials descriptors. The focus is laid on using the sure independence screening and sparsifying operator (SISSO) for regression.
python test.py
jupyter-notebook tutorial.ipynb
This diff is collapsed.
File added
Jmol.___JmolDate="$Date: 2018-06-15 14:15:06 +0200 (Fri, 15 Jun 2018) $"
Jmol.___fullJmolProperties="src/org/jmol/viewer/Jmol.properties"
Jmol.___JmolVersion="14.29.17"
Clazz.declarePackage ("J.adapter.readers.aflow");
Clazz.load (["J.adapter.readers.xtal.VaspPoscarReader", "java.util.Hashtable"], "J.adapter.readers.aflow.AFLOWReader", ["java.lang.Float", "java.util.Arrays", "JU.BS", "$.Lst", "$.PT", "$.SB", "JU.Logger"], function () {
c$ = Clazz.decorateAsClass (function () {
this.aabb = null;
this.readPRE = false;
this.fracB = NaN;
this.compositions = null;
this.getComposition = false;
this.listKey = null;
this.listKeyCase = null;
this.fileModelNumber = 0;
this.havePRE = false;
this.titleMsg = null;
this.keyMap = null;
Clazz.instantialize (this, arguments);
}, J.adapter.readers.aflow, "AFLOWReader", J.adapter.readers.xtal.VaspPoscarReader);
Clazz.prepareFields (c$, function () {
this.keyMap = new java.util.Hashtable ();
});
Clazz.overrideMethod (c$, "initializeReader",
function () {
this.readPRE = this.checkFilterKey ("PRE");
var s;
s = this.getFilter ("CA=");
if (s != null) this.fracB = (1 - this.parseFloatStr (s));
s = this.getFilter ("CB=");
if (s != null) this.fracB = this.parseFloatStr (s);
s = this.getFilter ("LIST=");
this.listKey = (s == null ? "HF" : s);
this.listKeyCase = this.listKey;
this.getComposition = !Float.isNaN (this.fracB);
this.discardLinesUntilStartsWith ("[");
this.aabb = this.line.substring (1, this.line.indexOf ("]"));
var pt = (JU.PT.isUpperCase (this.aabb.charAt (1)) ? 1 : 2);
this.defaultLabels = Clazz.newArray (-1, [this.aabb.substring (0, pt), this.aabb.substring (pt)]);
while (this.rd ().indexOf ("] REFERENCE:") >= 0) this.appendLoadNote (this.line);
this.compositions = new java.util.Hashtable ();
this.quiet = true;
this.asc.bsAtoms = new JU.BS ();
this.addJmolScript ("unitcell off;axes off;");
this.havePRE = (this.line.indexOf ("Structure PRE") >= 0);
});
Clazz.overrideMethod (c$, "checkLine",
function () {
if (!this.havePRE) this.discardLinesUntilContains ("Structure PRE");
this.havePRE = false;
if (this.line == null) return false;
this.continuing = new Boolean (this.continuing & this.readPrePost ()).valueOf ();
return this.continuing;
});
Clazz.defineMethod (c$, "readPrePost",
function () {
this.fileModelNumber++;
this.titleMsg = "#" + (this.modelNumber + 1) + (this.getComposition ? "," + this.fileModelNumber + ", Cb=" + this.fracB : "");
this.elementLabel = null;
var n0 = this.asc.bsAtoms.cardinality ();
if (this.readPRE) {
this.readStructure (this.titleMsg);
} else {
this.readElementLabelsOnly ();
this.discardLinesUntilContains ("Structure POST");
this.readStructure (this.titleMsg);
}if (this.getData ()) {
this.applySymmetryAndSetTrajectory ();
} else {
this.asc.bsAtoms.clearBits (this.asc.getLastAtomSetAtomIndex (), this.asc.ac);
this.doCheckUnitCell = false;
}this.finalizeModel ();
if (n0 != this.asc.bsAtoms.cardinality ()) JU.Logger.info ("AFLOW: file#, saved#, atoms: " + this.fileModelNumber + " " + this.modelNumber + " " + (this.asc.bsAtoms.cardinality () - n0));
return !this.haveModel || this.modelNumber != this.desiredModelNumber;
});
Clazz.defineMethod (c$, "finalizeModel",
function () {
this.asc.removeLastUnselectedAtoms ();
});
Clazz.defineMethod (c$, "readElementLabelsOnly",
function () {
this.readLines (5);
this.rdline ();
var n = this.getTokens ().length;
this.elementLabel = new Array (n);
this.rdline ();
this.line = "";
var s = null;
var last = null;
for (var i = 0; i < n; i++) {
while (s == null || s.equals (last)) {
this.rdline ();
var tokens = this.getTokens ();
if (tokens.length != 4 || (s = this.elementLabel[i] = this.getElement (tokens[3])) == null) {
i = n + 1;
break;
}}
last = s;
}
if (s == null) this.elementLabel = this.defaultLabels;
});
Clazz.defineMethod (c$, "getData",
function () {
this.discardLinesUntilContains ("- DATA -");
var htAFLOW = new java.util.Hashtable ();
htAFLOW.put ("fileModelNumber", Integer.$valueOf (this.fileModelNumber));
htAFLOW.put ("modelNumber", Integer.$valueOf (this.modelNumber + 1));
htAFLOW.put ("AaBb", this.aabb);
var pt = 0;
var sb = new JU.SB ();
var listVal = 3.4028235E38;
var strcb = "?";
var listValStr = null;
var cb = 0;
while (this.rdline () != null && (pt = this.line.indexOf (" # ")) >= 0) {
var key = this.line.substring (pt + 3).trim ();
var val = this.line.substring (0, pt).trim ();
sb.append (key).append ("=").append (val).append (" | ");
if (key.toUpperCase ().startsWith (this.listKey)) {
this.listKey = key.toUpperCase ();
this.listKeyCase = key;
listValStr = val;
listVal = this.parseFloatStr (val);
}if (key.equals ("Ca")) {
var ca = this.parseFloatStr (val);
if (this.getComposition && Math.abs ((1 - ca) - this.fracB) > 0.01) return false;
} else if (key.equals ("Cb")) {
cb = this.parseFloatStr (strcb = val);
if (this.getComposition && Math.abs (cb - this.fracB) > 0.01) return false;
} else if (key.equals ("Hf_atom [eV] (VASP)")) {
var e = this.parseFloatStr (val);
this.asc.setAtomSetEnergy (val, e);
}}
this.asc.setAtomSetName (this.titleMsg + (this.getComposition ? "" : " Cb=" + cb) + " " + this.listKey + "=" + listValStr);
var count_min = this.compositions.get (strcb);
if (!this.doGetModel (++this.modelNumber, null)) return false;
if (count_min == null) this.compositions.put (strcb, count_min = Clazz.newFloatArray (-1, [0, 3.4028235E38, 0]));
count_min[0]++;
if (listVal < count_min[1]) {
count_min[1] = listVal;
count_min[2] = this.fileModelNumber;
}while (this.line.indexOf ("- URL -") < 0) this.rdline ();
sb.append ("URL=" + this.rdline () + "|");
while (this.line.indexOf ("aurl=") < 0) this.rdline ();
sb.append (this.line);
var pairs = JU.PT.split (sb.toString (), " | ");
for (var i = pairs.length; --i >= 0; ) {
var kv = pairs[i].$plit ("=");
if (kv.length < 2) continue;
var f = this.parseFloatStr (kv[1]);
var o = Float.isNaN (f) ? kv[1] : Float.$valueOf (f);
htAFLOW.put (kv[0], o);
var kvclean = this.cleanKey (kv[0]);
if (kvclean !== kv[0]) htAFLOW.put (kvclean, o);
}
this.asc.setCurrentModelInfo ("aflowInfo", htAFLOW);
return true;
});
Clazz.defineMethod (c$, "cleanKey",
function (key) {
var kclean = this.keyMap.get (key);
if (kclean != null) return kclean;
var chars = key.toCharArray ();
for (var i = chars.length; --i >= 0; ) if (!JU.PT.isLetterOrDigit (chars[i])) chars[i] = '_';
this.keyMap.put (key, kclean = JU.PT.trim (JU.PT.rep ( String.instantialize (chars), "__", "_"), "_"));
return kclean;
}, "~S");
Clazz.overrideMethod (c$, "finalizeSubclassReader",
function () {
this.alignUnitCells ();
this.listCompositions ();
this.finalizeReaderASCR ();
});
Clazz.defineMethod (c$, "listCompositions",
function () {
var list = new JU.Lst ();
for (var e, $e = this.compositions.entrySet ().iterator (); $e.hasNext () && ((e = $e.next ()) || true);) {
var count_min = e.getValue ();
list.addLast (e.getKey () + "\t" + (Clazz.floatToInt (count_min[0])) + "\t" + Clazz.floatToInt (count_min[2]) + "\t" + this.listKeyCase + "\t" + count_min[1]);
}
var a = new Array (list.size ());
list.toArray (a);
java.util.Arrays.sort (a);
for (var i = 0, n = a.length; i < n; i++) this.appendLoadNote (this.aabb + "\t" + a[i]);
});
Clazz.defineMethod (c$, "alignUnitCells",
function () {
});
});
Clazz.declarePackage ("J.adapter.readers.cif");
Clazz.load (["JU.CifDataParser"], "J.adapter.readers.cif.Cif2DataParser", ["java.lang.Float", "java.util.Hashtable", "JU.Lst", "$.PT"], function () {
c$ = Clazz.declareType (J.adapter.readers.cif, "Cif2DataParser", JU.CifDataParser);
Clazz.overrideMethod (c$, "getVersion",
function () {
return 2;
});
Clazz.overrideMethod (c$, "toUnicode",
function (data) {
return data;
}, "~S");
Clazz.overrideMethod (c$, "isQuote",
function (ch) {
switch (ch) {
case '\1':
case '\'':
case '\"':
case '[':
case ']':
case '{':
case '}':
case ';':
return true;
}
return false;
}, "~S");
Clazz.overrideMethod (c$, "getQuotedStringOrObject",
function (ch) {
return this.processQuotedString ();
}, "~S");
Clazz.overrideMethod (c$, "preprocessString",
function () {
this.line = (this.ich == 0 ? this.str : this.str.substring (this.ich));
return this.setString (this.processSemiString ());
});
Clazz.defineMethod (c$, "processQuotedString",
function () {
var str = null;
var quoteChar = this.str.charAt (this.ich);
var tripleChar = null;
try {
switch (quoteChar) {
case '\1':
str = this.str.substring (1, (this.ich = this.str.indexOf ("\1", this.ich + 1)));
this.ich++;
break;
case '[':
return this.readList ();
case ']':
this.ich++;
return "]";
case '{':
return this.readTable ();
case '}':
this.ich++;
return "}";
case '\'':
case '"':
if (this.str.indexOf ("'''") == this.ich) tripleChar = "'''";
else if (this.str.indexOf ("\"\"\"") == this.ich) tripleChar = "\"\"\"";
var nchar = (tripleChar == null ? 1 : 3);
var pt = this.ich + nchar;
var pt1 = 0;
while ((pt1 = (tripleChar == null ? this.str.indexOf (quoteChar, pt) : this.str.indexOf (tripleChar, pt))) < 0) {
if (this.readLine () == null) break;
this.str += this.line;
}
this.ich = pt1 + nchar;
this.cch = this.str.length;
str = this.str.substring (pt, pt1);
break;
}
} catch (e) {
if (Clazz.exceptionOf (e, Exception)) {
System.out.println ("exception in Cif2DataParser ; " + e);
} else {
throw e;
}
}
return (this.cterm == '\0' || this.asObject ? str : JU.PT.esc (str));
});
Clazz.defineMethod (c$, "processSemiString",
function () {
var pt1;
var pt2;
var str = this.preprocessSemiString ();
if (str.indexOf (';') != 1 && (pt1 = str.indexOf ('\\')) > 1 && ((pt2 = str.indexOf ('\n')) > pt1 || pt2 < 0)) {
var prefix = str.substring (1, pt1);
str = JU.PT.rep (str, "\n" + prefix, "\n");
str = "\1" + str.substring (str.charAt (pt1 + 1) == '\\' ? pt1 + 1 : pt2 < 0 ? str.length - 1 : pt2 + 1);
}this.ich = 0;
return this.fixLineFolding (str);
});
Clazz.defineMethod (c$, "readList",
function () {
this.ich++;
var cterm0 = this.cterm;
this.cterm = ']';
var ns = this.nullString;
this.nullString = null;
var lst = (this.asObject ? new JU.Lst () : null);
var n = 0;
var str = "";
while (true) {
var value = (this.asObject ? this.getNextTokenObject () : this.getNextToken ());
if (value == null || value.equals ("]")) break;
if (this.asObject) {
lst.addLast (value);
} else {
if (n++ > 0) str += ",";
str += value;
}}
this.cterm = cterm0;
this.nullString = ns;
return (this.asObject ? lst : "[" + str + "]");
});
Clazz.defineMethod (c$, "readTable",
function () {
this.ich++;
var cterm0 = this.cterm;
this.cterm = '}';
var ns = this.nullString;
this.nullString = null;
var map = (this.asObject ? new java.util.Hashtable () : null);
var n = 0;
var str = "";
while (true) {
var key = this.getNextToken ();
if (key == null || key.equals ("}")) break;
while (this.isSpaceOrColon (this.ich)) this.ich++;
if (this.asObject) {
map.put (key, this.getNextTokenObject ());
} else {
if (n++ > 0) str += ",";
str += key + " : " + this.getNextToken ();
}}
this.cterm = cterm0;
this.nullString = ns;
return (this.asObject ? map : "{" + str + "}");
});
Clazz.defineMethod (c$, "isSpaceOrColon",
function (ich) {
if (ich < this.cch) switch (this.line.charAt (ich)) {
case ' ':
case '\t':
case '\n':
case ':':
return true;
}
return false;
}, "~N");
Clazz.overrideMethod (c$, "unquoted",
function (s) {
if (this.cterm == '\0' && !this.asObject) return s;
var n = s.length;
if (n > 0) {
var c = s.charAt (0);
if (JU.PT.isDigit (c) || c == '-' || c == '.' && n > 1) {
var pt = s.indexOf ('(');
var isFloat = (s.indexOf (".") >= 0);
if (n > 1 && pt > 0 && s.indexOf (')', pt + 1) == n - 1) s = s.substring (0, pt);
try {
if (isFloat) {
var f = Float.parseFloat (s);
if (this.asObject) return Float.$valueOf (f);
s = "" + f;
if (s.indexOf (".") < 0 && s.indexOf ("E") < 0) s += ".0";
return s;
}var i = Integer.parseInt (s);
return (this.asObject ? Integer.$valueOf (i) : "" + i);
} catch (e) {
}
}}return (this.asObject ? s : JU.PT.esc (s));
}, "~S");
Clazz.defineMethod (c$, "fixLineFolding",
function (str) {
if (str.indexOf ('\\') < 0) return str;
var n = str.length;
if (str.endsWith ("\\\1")) str = str.substring (0, n - 1) + "\n\1";
var pt = 0;
while ((pt = str.indexOf ('\\', pt + 1)) >= 0) {
var eol = str.indexOf ('\n', pt);
if (eol < 0) break;
for (var i = eol; --i > pt; ) {
var ch = str.charAt (i);
if (!JU.PT.isWhitespace (ch)) {
if (ch == '\\') {
pt = i;
break;
}pt = eol;
break;
}}
if (pt < eol) str = str.substring (0, pt) + str.substring (eol + 1);
}
return str;
}, "~S");
c$.getArrayFromStringList = Clazz.defineMethod (c$, "getArrayFromStringList",
function (s, n) {
var f = Clazz.newFloatArray (n, 0);
JU.PT.parseFloatArrayInfested (JU.PT.getTokens (s.$replace (',', ' ').$replace ('[', ' ')), f);
var d = Clazz.newDoubleArray (n, 0);
for (var i = 0; i < n; i++) d[i] = f[i];
return d;
}, "~S,~N");
});
Clazz.declarePackage ("J.adapter.readers.cif");
Clazz.load (["J.adapter.readers.cif.CifReader"], "J.adapter.readers.cif.Cif2Reader", ["J.adapter.readers.cif.Cif2DataParser"], function () {
c$ = Clazz.declareType (J.adapter.readers.cif, "Cif2Reader", J.adapter.readers.cif.CifReader);
Clazz.overrideMethod (c$, "getCifDataParser",
function () {
return new J.adapter.readers.cif.Cif2DataParser ().set (this, null, this.debugging);
});
});
This diff is collapsed.
This diff is collapsed.
Clazz.declarePackage ("J.adapter.readers.cif");
Clazz.load (null, "J.adapter.readers.cif.MMCifValidationParser", ["java.lang.Character", "java.util.Hashtable", "JU.Lst", "$.PT", "JS.SV", "JU.Logger"], function () {
c$ = Clazz.decorateAsClass (function () {
this.asResidues = false;
this.reader = null;
this.resMap = null;
this.atomMap = null;
Clazz.instantialize (this, arguments);
}, J.adapter.readers.cif, "MMCifValidationParser");
Clazz.makeConstructor (c$,
function () {
});
Clazz.defineMethod (c$, "set",
function (reader) {
this.reader = reader;
this.asResidues = reader.checkFilterKey ("ASRES");
return this;
}, "J.adapter.smarter.AtomSetCollectionReader");
Clazz.defineMethod (c$, "finalizeValidations",
function (vwr, modelMap) {
var map = this.reader.dssr;
if (map != null) return vwr.getAnnotationParser (true).fixDSSRJSONMap (map);
this.mapAtomResIDs (modelMap);
var svMap = this.reader.validation;
var retProps = this.reader.vwr.getAnnotationParser (false).catalogValidations (this.reader.vwr, svMap, this.getModelAtomIndices (), this.resMap, (this.asResidues ? null : this.atomMap), modelMap);
var note = (retProps == null || retProps.size () == 0 ? null : this.setProperties (retProps));
svMap.mapPut ("_note", JS.SV.newS (note));
return note;
}, "JV.Viewer,java.util.Map");
Clazz.defineMethod (c$, "finalizeRna3d",
function (modelMap) {
this.mapAtomResIDs (modelMap);
var svMap = this.getRna3dMap (this.reader.addedData);
var note = this.reader.vwr.getAnnotationParser (false).catalogStructureUnits (this.reader.vwr, svMap, this.getModelAtomIndices (), this.resMap, null, modelMap);
svMap.mapPut ("_note", JS.SV.newS (note));
for (var i = this.reader.asc.atomSetCount; --i >= 0; ) {
var info = this.reader.asc.getAtomSetAuxiliaryInfo (i);
info.put ("rna3d", svMap);
}
return note;
}, "java.util.Map");
Clazz.defineMethod (c$, "getRna3dMap",
function (addedData) {
var map = new java.util.Hashtable ();
var next = Clazz.newIntArray (1, 0);
var id = "";
while ((id = JU.PT.getQuotedStringNext (addedData, next)).length > 0) {
var units = JU.PT.getQuotedStringNext (addedData, next);
var type = "?";
switch (id.charAt (0)) {
case 'H':
type = "hairpinLoops";
break;
case 'I':
type = "internalLoops";
break;
case 'J':
type = "junctions";
break;
default:
JU.Logger.error ("MMCif could not read: " + id + " " + units);
continue;
}
var list = map.get (type);
if (list == null) map.put (type, list = new JU.Lst ());
var m = new java.util.Hashtable ();
m.put ("index", Integer.$valueOf (JU.PT.parseInt (id.substring (id.lastIndexOf ("_") + 1))));
m.put ("units", units);
list.addLast (m);
}
return JS.SV.getVariableMap (map);
}, "~S");
Clazz.defineMethod (c$, "mapAtomResIDs",
function (modelMap) {
var atoms = this.reader.asc.atoms;
this.resMap = new java.util.Hashtable ();
this.atomMap = new java.util.Hashtable ();
var iresLast = -1;
var resLast = null;
var smodel = "" + modelMap.get ("_0");
for (var i = 0, model = 1, i0 = 0, n = this.reader.asc.getAtomSetAtomCount (0); i < n; i++) {
var a = atoms[i];
var ires = a.sequenceNumber;
var res = smodel + "_" + a.chainID + "_" + ires + "_" + (a.insertionCode == '\0' ? "" : "" + a.insertionCode);
var atom = res + "_" + a.atomName.toUpperCase () + "_" + (a.altLoc == '\0' ? "" : "" + Character.toLowerCase (a.altLoc));
var ia = Integer.$valueOf (i - i0);
if (ires != iresLast) {
iresLast = ires;
if (resLast != null) resLast[1] = i - i0;
this.resMap.put (res, resLast = Clazz.newIntArray (-1, [i - i0, n]));
}this.atomMap.put (atom, ia);
if (i == n - 1) {
i0 += n;
n = this.reader.asc.getAtomSetAtomCount (model++);
}}
}, "java.util.Map");
Clazz.defineMethod (c$, "getModelAtomIndices",
function () {
var indices = Clazz.newIntArray (this.reader.asc.atomSetCount + 1, 0);
for (var m = indices.length - 1; --m >= 0; ) indices[m] = this.reader.baseAtomIndex + this.reader.asc.getAtomSetAtomIndex (m);
indices[indices.length - 1] = this.reader.asc.ac;
return indices;
});
Clazz.defineMethod (c$, "setProperties",
function (propList) {
var note = "Validations loaded:";
for (var i = 0, n = propList.size (); i < n; ) {
var key = propList.get (i++);
var f = propList.get (i++);
var model = (propList.get (i++)).intValue ();
var isGroup = (propList.get (i++)).booleanValue ();
var count = 0;