Skip to content

Commit

Permalink
Merge pull request #171 from sys-bio/sbmlwarning
Browse files Browse the repository at this point in the history
Sbmlwarning
  • Loading branch information
evaxliu authored Oct 3, 2023
2 parents ee87548 + f4fc2f7 commit cc1e0b7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/BioModels/1.ant
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ model *BIOMD0000000001()
const comp1, t2, kr_0, kr_1, kf_2, kr_2, kr_3, kr_4, kf_5, kr_5, kf_6, kr_6;
const kr_7, kr_8, kf_9, kr_9, kf_10, kr_10, kf_11, kr_11, kr_12, kr_13;
const kf_14, kr_14, kf_15, kr_15, kf_16, kr_16;
unit kf_17 = 1.66057788110262e;

// Display Names:
comp1 is "compartment1";
Expand Down
4 changes: 2 additions & 2 deletions vscode-antimony/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions vscode-antimony/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,31 @@ export async function activate(context: vscode.ExtensionContext) {
if (path.extname(vscode.window.activeTextEditor.document.fileName) === '.xml' && roundTripping) {
triggerSBMLEditor(vscode.window.activeTextEditor.document, sbmlFileNameToPath);
}
if (fileExtension == '.xml') {
vscode.commands.executeCommand('antimony.checkSbml', doc.uri.path).then((result: any) => {
if (result === true) {
vscode.window.showWarningMessage("This SBML file contains notes, model history, algebraic rules and unsupported packages. Proceed conversion to Antimony with caution.")
}
});
}
}

vscode.window.onDidChangeActiveTextEditor(() => {
const activeTextEditor = vscode.window.activeTextEditor;
if (activeTextEditor) {
const doc = activeTextEditor.document;
const uri = doc.uri.toString();
const fileExtension = path.extname(uri);
if (fileExtension == '.xml') {
vscode.commands.executeCommand('antimony.checkSbml', doc.uri.path).then((result: any) => {
if (result === true) {
vscode.window.showWarningMessage("This SBML file contains notes, model history, algebraic rules, and/or unsupported packages. Proceed conversion to Antimony with caution.");
}
});
}
}
});

async function triggerSBMLEditor(event: TextDocument, sbmlFileNameToPath: Map<any, any>) {
await client.onReady();

Expand Down Expand Up @@ -696,7 +719,6 @@ export async function createVirtualEnv(context: vscode.ExtensionContext) {
.then(async selection => {
if (selection === 'Yes') {
installEnv();
vscode.env.openExternal(vscode.Uri.parse("https://github.com/sys-bio/vscode-antimony#installation-required-1"));
} else if (selection === 'No') {
vscode.window.showInformationMessage('The default python interpreter will be used.');
}
Expand Down Expand Up @@ -893,7 +915,6 @@ async function deleteVirtualEnv(message) {
promptToReloadWindow("Reload for changes to take effect.")
}
} else if (selection === 'No') {
vscode.env.openExternal(vscode.Uri.parse("https://github.com/sys-bio/vscode-antimony#installation-required-1"));
vscode.window.showWarningMessage(`The extension will not work without deleting and reinstalling the virtual environment.`, {modal: true}, action)
.then(selectedAction => {
if (selectedAction === action) {
Expand Down
65 changes: 64 additions & 1 deletion vscode-antimony/src/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import antimony

from libsbml import *

sys.path.append(os.path.join(EXTENSION_ROOT, "server", "stibium"))

from stibium.parse import AntimonyParser
Expand Down Expand Up @@ -51,7 +53,6 @@
antfile_cache = None
uri = None


#### Annotations ####
@server.command('antimony.getAnnotated')
def get_annotated(ls: LanguageServer, args):
Expand Down Expand Up @@ -239,6 +240,68 @@ def get_rate_law_dict(ls: LanguageServer, args):
}
return reader.relevant_rate_laws

#### Check sbml files ####
@server.thread()
@server.command('antimony.checkSbml')
def check_sbml(ls: LanguageServer, args):
feature_exists = False
sbml = args[0]
sbml_doc = readSBML(sbml)
model = sbml_doc.getModel()

# Check for packages
if model.isPackageEnabled('comp'):
# vscode_logger.info('Comp Package is enabled')
feature_exists = True
elif model.isPackageEnabled('fbc'):
# vscode_logger.info('FBC Package is enabled')
feature_exists = True
elif model.isPackageEnabled('distrib'):
# vscode_logger.info('Distrib Package is enabled')
feature_exists = True
elif model.isPackageEnabled('layout'):
# vscode_logger.info('Layout Package is enabled')
feature_exists = True
elif model.isPackageEnabled('render'):
# vscode_logger.info('Render Package is enabled')
feature_exists = True
elif model.isPackageEnabled('spatial'):
# vscode_logger.info('Spatial Package is enabled')
feature_exists = True
elif model.isPackageEnabled('multi'):
# vscode_logger.info('Multi Package is enabled')
feature_exists = True
elif model.isPackageEnabled('qual'):
# vscode_logger.info('Qual Package is enabled')
feature_exists = True

# Check for model history
if model.isSetModelHistory():
# vscode_logger.info('Model History is set')
feature_exists = True

# Check for Notes
elementsList = sbml_doc.getListOfAllElements()
# vscode_logger.info('List of Elements: ')
# vscode_logger.info(sbml_doc.getListOfAllElements())
# vscode_logger.info('elementsList')
for x in elementsList:
# vscode_logger.info(x)
if (x.isSetNotes()):
# vscode_logger.info('Notes are set')
feature_exists = True

# Check for Algebraic Rules
for r in range(model.getNumRules()):
rule = model.getRule(r)
# vscode_logger.info('Rule Type Code: ')
# vscode_logger.info(rule.getTypeCode())
if rule.getTypeCode() == SBML_ALGEBRAIC_RULE:
# vscode_logger.info('Algebraic Rule is set')
feature_exists = True

return feature_exists

# @server.thread()
# @server.command('antimony.recommender')
# def recommend(ls: LanguageServer, args):
Expand Down

0 comments on commit cc1e0b7

Please sign in to comment.