Skip to content

Commit

Permalink
Fixed a bug that avoided charging one atom
Browse files Browse the repository at this point in the history
The cif file inputted needs to end in a newline. If not, things go awry.
  • Loading branch information
patrickfuller committed Aug 3, 2013
1 parent 6cf8fc7 commit 5983a73
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
21 changes: 12 additions & 9 deletions eqeq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
2. to enable scaling of simulations to millions of structures.
"""
from ctypes import cdll, c_char_p, c_int, c_double, c_float
import json
import json_formatter as json
import os
import sys

Expand Down Expand Up @@ -37,7 +37,7 @@ def run(structure, input_type="cif", output_type="cif", l=1.2, h_i0=-2.0,
input_type: (Optional) Specifies input type. Can be anything supported
by openbabel, as well as "json"
output_type: (Optional) Specifies the output type. Currently, options
are "cif", "mol", "pdb", "car", "json", "object", and "files". The
are "cif", "mol", "pdb", "car", "json", "list", and "files". The
first four return modified chemical data formats, "object" returns
a Python object, "json" is that object serialized, and "files"
saves files of all possible output types.
Expand All @@ -63,23 +63,26 @@ def run(structure, input_type="cif", output_type="cif", l=1.2, h_i0=-2.0,
"""
# Error handling on string params. Should spare users some annoyance.
o, m = output_type.lower(), method.lower()
if o not in ["cif", "pdb", "car", "mol", "json", "object", "files"]:
if o not in ["cif", "pdb", "car", "mol", "json", "list", "files"]:
raise NotImplementedError("Output format '%s' is not supported!" % o)
if m not in ["direct", "nonperiodic", "ewald"]:
raise NotImplementedError("Method '%s' is not supported!" % m)
# If linked to openbabel, use it to handle json interconversion externally
if input_type != "cif":
structure = format_converter.convert(structure, input_type, "cif")
# Calls libeqeq.so's run method, returning a string of data
result = eqeq.run(structure, output_type, l, h_i0, charge_precision,
method, m_r, m_k, eta, ionization_data_path,
charge_data_path)
result = eqeq.run(structure, ("json" if output_type == "list" else
output_type), l, h_i0, charge_precision, method, m_r,
m_k, eta, ionization_data_path, charge_data_path)
if output_type == "list":
return json.loads(result)
# This option appends atoms in json/object data with a "charge" attribute
if output_type in ["json", "object"]:
if output_type == "json":
obj = format_converter.convert(structure, "cif", "object")
for atom, charge in zip(obj["atoms"], json.loads(result)):
result = json.loads(result)
for atom, charge in zip(obj["atoms"], result):
atom["charge"] = charge
result = obj if output_type == "object" else json.dumps(obj)
result = json.dumps(obj)
return result


Expand Down
2 changes: 1 addition & 1 deletion format_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def json_to_cif(mof):
% tuple([atom["element"], i, atom["element"]] +
cartesian_to_fractional(atom["location"], va, vb, vc))
for i, atom in enumerate(mof["atoms"]))
return cif
return cif + "\n"


def get_angle(first_vector, second_vector):
Expand Down
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ char *run(const char *data, const char *outputType, double _lambda, float _hI0,
outString = OutputMOLData();
} else if (type.compare("car") == 0) {
outString = OutputCARData();
} else if (type.compare("json") == 0 || type.compare("object") == 0) {
} else if (type.compare("json") == 0) {
outString = OutputJSONData();
} else {
cerr << "Output type \"" << outputType << "\" not supported!" << endl;
Expand Down Expand Up @@ -974,10 +974,10 @@ string OutputPDBData() {
string OutputJSONData() {
ostringstream stringStream;
stringStream << "[";
for (int i = 0; i < numAtoms; i++) {
for (int i = 0; i < numAtoms - 1; i++) {
stringStream << Q[i] << ",";
}
stringStream << Q[numAtoms] << "]";
stringStream << Q[numAtoms - 1] << "]";
return stringStream.str();
}
/*****************************************************************************/
Expand Down

0 comments on commit 5983a73

Please sign in to comment.