//returns a hop based on the information on the line
Hop getHopFromLine(string line){
    Hop hop = createHop(-1, -1, -1);

    char *tokens;
    char *charLine = (char *)malloc(sizeof(char) * line.size());
    
    strcpy(charLine, line.c_str());
    tokens = strtok(charLine, " ");
    int tokenNumber = 0;
    while(tokens != NULL){
        switch(tokenNumber){
            case 0:
                hop.atom1 = atoi(tokens);
                break;
            case 1:
                hop.atom2 = atoi(tokens);
                break;
            case 2:
                hop.hop = atoi(tokens);
                break;
        }
        tokens = strtok(NULL, " ");
        tokenNumber++;
    }
    return hop;
}
Exemplo n.º 2
0
Hop
RouteParser::createHop(stringref str)
{
    if (str.empty()) {
        return Hop().addDirective(createErrorDirective("Failed to parse empty string."));
    }
    size_t len = str.size();
    if (len > 1 && str[0] == '?') {
        Hop hop = createHop(str.substr(1));
        hop.setIgnoreResult(true);
        return hop;
    }
    if (len > 4 && str.substr(0, 4) == "tcp/") {
        IHopDirective::SP tcp = createTcpDirective(str.substr(4));
        if (tcp.get() != nullptr) {
            return Hop().addDirective(tcp);
        }
    }
    if (len > 6 && str.substr(0, 6) == "route:") {
        return Hop().addDirective(createRouteDirective(str.substr(6)));
    }
    Hop ret;
    for (size_t from = 0, at = 0, depth = 0; at <= len; ++at) {
        if (at == len || (depth == 0 && str[at] == '/')) {
            if (depth > 0) {
                return Hop().addDirective(createErrorDirective(
                                "Unexpected token '': syntax error"));
            }
            ret.addDirective(createDirective(str.substr(from, at - from)));
            from = at + 1;
        } else if (isWhitespace(str[at]) && depth == 0) {
            return Hop().addDirective(createErrorDirective(
                            vespalib::make_string(
                                    "Failed to completely parse '%s'.",
                                    vespalib::string(str).c_str())));
        } else if (str[at] == '[') {
            ++depth;
        } else if (str[at] == ']') {
            if (depth == 0) {
                return Hop().addDirective(createErrorDirective(
                                "Unexpected token ']': syntax error"));
            }
            --depth;
        }
    }
    return ret;
}
Exemplo n.º 3
0
Route
RouteParser::createRoute(stringref str)
{
    Route ret;
    for (size_t from = 0, at = 0, depth = 0; at <= str.size(); ++at) {
        if (at == str.size() || (depth == 0 && isWhitespace(str[at]))) {
            if (from < at - 1) {
                Hop hop = createHop(str.substr(from, at - from));
                if (hop.hasDirectives() &&
                    hop.getDirective(0)->getType() == IHopDirective::TYPE_ERROR)
                {
                    return std::move(Route().addHop(std::move(hop)));
                }
                ret.addHop(std::move(hop));
            }
            from = at + 1;
        } else if (str[at] == '[') {
            ++depth;
        } else if (str[at] == ']') {
            --depth;
        }
    }
    return ret;
}
Exemplo n.º 4
0
Molecule createMeshZMolecules(Opls_Scan *scanner)
{

    //1 S    200    0    0    0.000000   0    0.000000   0    0.000000        0  
    Atom atom1=scanner->getAtom("200");
    atom1.id=1;

    // 2 DUM   -1    0    1    0.500000   0    0.000000   0    0.000000        0
    Atom atom2=createAtom(2,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond2=createBond(2,1,0.5,false);

    //3 DUM   -1    0    2    0.500000   1   90.000000   0    0.000000        0 
    Atom atom3=createAtom(3,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond3=createBond(3,2,0.5,false);
    Angle angle3=createAngle(3,1,90,false);

    //4 hH    204    0    1    1.336532   2   90.000000   3  180.000000        0    
    Atom atom4=scanner->getAtom("204");
    atom4.id=4;
    Bond bond4=createBond(4,1,1.336532,true);
    Angle angle4=createAngle(4,2,90,false);
    Dihedral dihed4=createDihedral(4,3,180,false);

    //5 C    217    0    1    1.811119   4   96.401770   2  180.000000        0
    Atom atom5=scanner->getAtom("217");
    atom5.id=5;
    Bond bond5=createBond(5,1,1.811119,true);
    Angle angle5=createAngle(5,4,96.401770,true);
    Dihedral dihed5=createDihedral(5,2,180,false);

    //6 HC   140    0    5    1.090187   1  110.255589   4  179.999947        0
    Atom atom6=scanner->getAtom("140");
    atom6.id=6;
    Bond bond6=createBond(6,5,1.090187,true);
    Angle angle6=createAngle(6,1,110.255589,true);
    Dihedral dihed6=createDihedral(6,4,179.999947,true);    

    //7 HC   140    0    5    1.090135   6  108.527646   1  121.053891        0
    Atom atom7=scanner->getAtom("140");
    atom7.id=7;
    Bond bond7=createBond(7,5,1.090135,true);
    Angle angle7=createAngle(7,6,108.527646,true);
    Dihedral dihed7=createDihedral(7,1,121.053891,true);    

    //8 HC   140    0    5    1.090135   6  108.527646   1  238.946114        0
    Atom atom8=scanner->getAtom("140");
    atom8.id=8;
    Bond bond8=createBond(8,5,1.090135,true);
    Angle angle8=createAngle(8,6,108.527646,true);
    Dihedral dihed8=createDihedral(8,1,238.946114,true);

    /* HOPS and BONDS Diagram of Mesh.z
    //      1--2--3
    //      |\
    //      | \
    //      4  5
    //        /|\
    //       / | \
    //      6  7  8
    */
    //All hops that have a hop distance >= 3

    Hop hop1= createHop(2,6,3);
    Hop hop2= createHop(2,7,3);
    Hop hop3= createHop(2,8,3);
    Hop hop4= createHop(3,4,3);
    Hop hop5= createHop(3,5,3);
    Hop hop6= createHop(3,6,4);
    Hop hop7= createHop(3,7,4);
    Hop hop8= createHop(3,8,4);
    Hop hop9= createHop(4,6,3);
    Hop hop10= createHop(4,7,3);
    Hop hop11= createHop(4,8,3);

    Atom *atomPtr = new Atom[8];
    Bond *bondPtr = new Bond[7];
    Angle *anglePtr = new Angle[6];
    Dihedral *dihedPtr = new Dihedral[5];
    Hop *hopPtr = new Hop[11];


    atomPtr[0]=atom1;  atomPtr[1]=atom2; atomPtr[2]=atom3; atomPtr[3]=atom4; atomPtr[4]=atom5; atomPtr[5]=atom6; atomPtr[6]=atom7; atomPtr[7]=atom8;
    bondPtr[0]=bond2; bondPtr[1]=bond3; bondPtr[2]=bond4; bondPtr[3]=bond5; bondPtr[4]=bond6; bondPtr[5]=bond7; bondPtr[6]=bond8;
    anglePtr[0]=angle3; anglePtr[1]=angle4; anglePtr[2]=angle5; anglePtr[3]=angle6; anglePtr[4]=angle7; anglePtr[5]=angle8;
    dihedPtr[0]=dihed4; dihedPtr[1]=dihed5; dihedPtr[2]=dihed6; dihedPtr[3]=dihed7; dihedPtr[4]=dihed8;
    hopPtr[0]=hop1; hopPtr[1]=hop2; hopPtr[2]=hop3; hopPtr[3]=hop4; hopPtr[4]=hop5; hopPtr[5]=hop6;  hopPtr[6]=hop7; hopPtr[7]=hop8; hopPtr[8]=hop9; 
    hopPtr[9]=hop10; hopPtr[10]=hop11;


    return createMolecule(1,atomPtr,anglePtr,bondPtr,dihedPtr,hopPtr,8,6,7,5,11);
}
Exemplo n.º 5
0
vector<Molecule> createT3pdimMolecules(Opls_Scan *scanner)
{
    // TIP3P Water Dimer                                      Tot. E =     -6.5396
    //1  O   111  111    0     .000000   0     .000000   0     .000000        0
    Atom atom1 = scanner->getAtom("111");
    atom1.id=1;    

    //2  DU   -1   -1    1    1.000000   0     .000000   0     .000000        0 
    Atom atom2=createAtom(2,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond2=createBond(2,1,1.0,false);   

    //3  DU   -1   -1    2    1.000000   1   90.000000   0     .000000        0
    Atom atom3=createAtom(3,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond3=createBond(3,2,1.0,false);
    Angle angle3=createAngle(3,1,90.0,false);    

    //4  HO  112  112    1     .957200   2  127.740000   3   90.000000        0
    Atom atom4=scanner->getAtom("112");
    atom4.id=4;
    Bond bond4=createBond(4,1,.957200,false);
    Angle angle4=createAngle(4,2,127.740000,false);
    Dihedral dihed4=createDihedral(4,3,90.00,false);

    //5  HO  112  112    1     .957200   4  104.520000   2  180.000000        0 
    Atom atom5=scanner->getAtom("112");
    atom5.id=5;
    Bond bond5=createBond(5,1,.957200,false);
    Angle angle5=createAngle(5,4,104.520000,false);
    Dihedral dihed5=createDihedral(5,2,180.00,false); 
     
    //6  X    -1   -1    1     .150000   4   52.260000   5     .000000        0
    Atom atom6=createAtom(6,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond6=createBond(6,1,.150000,false);
    Angle angle6=createAngle(6,4,52.260000,false);
    Dihedral dihed6=createDihedral(6,5,.00,false); 

    //TERZ 2nd Bonded Molecule                                                                           
    //7  O   111  111    1    2.751259   2  131.716186   3  269.946364        0
    Atom atom7=scanner->getAtom("111");
    atom7.id=7;
    Bond bond7=createBond(7,1,2.751259,false);
    Angle angle7=createAngle(7,2,131.716186,false);
    Dihedral dihed7=createDihedral(7,3,269.946364,false);

    //8  DU   -1   -1    7    1.000000   1   21.472391   2  179.887530        0
    Atom atom8=createAtom(8,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond8=createBond(8,7,1.0,false);
    Angle angle8=createAngle(8,1,21.472391,false);
    Dihedral dihed8=createDihedral(8,2,179.887530,false); 

    //9  DU   -1   -1    8    1.000000   7   90.000000   1  179.624613        0
    Atom atom9=createAtom(9,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond9=createBond(9,8,1.0,false);
    Angle angle9=createAngle(9,7,90.000000,false);
    Dihedral dihed9=createDihedral(9,1,179.624613,false); 

    //10  HO  112  112    7     .957200   8  127.740000   9   90.000000        0
    Atom atom10=scanner->getAtom("112");
    atom10.id=10;
    Bond bond10=createBond(10,7,0.957200,false);
    Angle angle10=createAngle(10,8,127.74,false);
    Dihedral dihed10=createDihedral(10,9,90.0,false);


    //11  HO  112  112    7     .957200  10  104.520000   8  180.000000        0
    Atom atom11=scanner->getAtom("112");
    atom11.id=11;
    Bond bond11=createBond(11,7,0.957200,false);
    Angle angle11=createAngle(11,10,104.52,false);
    Dihedral dihed11=createDihedral(11,8,180.0,false);

    //12  X    -1   -1    7     .150000  10   52.260000  11     .000000        0 
    Atom atom12=createAtom(12,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond12=createBond(12,7,0.15,false);
    Angle angle12=createAngle(12,10,52.26,false);
    Dihedral dihed12=createDihedral(12,11,0.0,false);

    /* HOPS and BONDS Diagram of Mesh.z
    //      
    //
    //      10  11 12
    //        \ | /
    //         \|/
    //          7--8--9
    //          |
    //          |
    //          1--2--3
    //         /|\
    //        / | \
    //       4  5  6
    */
    //All intermolecular hops that have a hop distance >= 3 

    //bottom Molecule 
    Hop hop1=createHop(3,4,3);
    Hop hop2=createHop(3,5,3);
    Hop hop3=createHop(3,6,3);
    //top Molecule 
    Hop hop4=createHop(9,10,3);
    Hop hop5=createHop(9,11,3);
    Hop hop6=createHop(9,12,3);

    Atom *atomPtr = new Atom[6];
    Bond *bondPtr = new Bond[5];
    Angle *anglePtr = new Angle[4];
    Dihedral *dihedPtr = new Dihedral[3];
    Hop *hopPtr = new Hop[3];
    vector<Molecule> retVect;

    atomPtr[0]=atom1; atomPtr[1]=atom2; atomPtr[2]=atom3; atomPtr[3]=atom4; atomPtr[4]=atom5; atomPtr[5]=atom6;
    bondPtr[0]=bond2; bondPtr[1]=bond3; bondPtr[2]=bond4; bondPtr[3]=bond5; bondPtr[4]=bond6;
    anglePtr[0]=angle3; anglePtr[1]=angle4; anglePtr[2]=angle5; anglePtr[3]=angle6;
    dihedPtr[0]=dihed4; dihedPtr[1]=dihed5; dihedPtr[2]=dihed6;
    hopPtr[0]=hop1; hopPtr[1]=hop2; hopPtr[2]=hop3;  
    retVect.push_back( createMolecule(1,atomPtr,anglePtr,bondPtr,dihedPtr,hopPtr,6,4,5,3,3) );

    Atom *atomPt = new Atom[6];
    Bond *bondPt = new Bond[6];
    Angle *anglePt = new Angle[6];
    Dihedral *dihedPt = new Dihedral[6];
    Hop *hopPt = new Hop[3];

    atomPt[0]=atom7; atomPt[1]=atom8; atomPt[2]=atom9; atomPt[3]=atom10; atomPt[4]=atom11; atomPt[5]=atom12;
    bondPt[0]=bond7; bondPt[1]=bond8; bondPt[2]=bond9; bondPt[3]=bond10; bondPt[4]=bond11;  bondPt[5]=bond12;
    anglePt[0]=angle7; anglePt[1]=angle8; anglePt[2]=angle9; anglePt[3]=angle10; anglePt[4]=angle11; anglePt[5]=angle12;
    dihedPt[0]=dihed7; dihedPt[1]=dihed8; dihedPt[2]=dihed9; dihedPt[3]=dihed10; dihedPt[4]=dihed11; dihedPt[5]=dihed12;
    hopPt[0]=hop4; hopPt[1]=hop5; hopPt[2]=hop6;  
    retVect.push_back( createMolecule(7,atomPt,anglePt,bondPt,dihedPt,hopPt,6,6,6,6,3) );

    return retVect;
}