REBOL [
  Title: "random_tree"
  File:   %random_tree.r
]


;**** Model class ****

random_tree: make object! [

  ;**** Output values ****

  C_FALSE: 0
  C_TRUE: 1

  ;**** Values of the attributes ****

  C_FG_CON2_NO: 0
  C_FG_CON2_YES: 1
  C_FG_COOH_NO: 0
  C_FG_COOH_YES: 1
  C_FG_COOR_NO: 0
  C_FG_COOR_YES: 1
  C_FG_F_NO: 0
  C_FG_F_YES: 1
  C_FG_PHOH_NO: 0
  C_FG_PHOH_YES: 1

  ;**** Properties ****

  Angles: 0.0
  Atoms: 0.0
  Bonds: 0.0
  ChiralAtms: 0.0
  Dipole: 0.0
  EzBnds: 0.0
  FG_CON2: 0
  FG_COOH: 0
  FG_COOR: 0
  FG_F: 0
  FG_PhOH: 0
  FlexTorsions: 0.0
  Gyrrad: 0.0
  HbAcc: 0.0
  HbDon: 0.0
  HeavyAtoms: 0.0
  Lipole: 0.0
  Mass: 0.0
  Ovality: 0.0
  Psa: 0.0
  Rings: 0.0
  Sas: 0.0
  Sav: 0.0
  Sdiam: 0.0
  Torsions: 0.0
  Vdiam: 0.0
  VirtualLogP: 0.0


  ;**** Classification method ****

  Classify: does [
    either HbDon < 0.5000 [
      either Sas < 756.1100 [
        if FG_COOR == C_FG_COOR_YES [
          either Angles < 106.5000 [
            either Atoms < 48.0000 [
              Res: C_TRUE
            ][
              either Atoms < 51.0000 [
                Res: C_FALSE
              ][
                Res: C_TRUE
              ]
            ]
          ][
            Res: C_FALSE
          ]
        ][
          either HeavyAtoms < 13.5000 [
            either Gyrrad < 2.8500 [
              Res: C_TRUE
            ][
              Res: C_FALSE
            ]
          ][
            Res: C_TRUE
          ]
        ]
      ][
        Res: C_FALSE
      ]
    ][
      either Angles < 92.5000 [
        either Gyrrad < 3.6800 [
          either Torsions < 17.5000 [
            either Sas < 283.4200 [
              Res: C_TRUE
            ][
              either FlexTorsions < 0.5000 [
                either Sas < 301.9000 [
                  Res: C_FALSE
                ][
                  Res: C_TRUE
                ]
              ][
                if FG_CON2 == C_FG_CON2_YES [
                  either Lipole < 2.1200 [
                    Res: C_TRUE
                  ][
                    Res: C_FALSE
                  ]
                ][
                  either HbAcc < 2.5000 [
                    either Rings < 1.5000 [
                      either Sav < 575.0000 [
                        Res: C_TRUE
                      ][
                        either Sdiam < 8.5700 [
                          Res: C_FALSE
                        ][
                          Res: C_TRUE
                        ]
                      ]
                    ][
                      either Torsions < 15.5000 [
                        Res: C_FALSE
                      ][
                        either HeavyAtoms < 15.5000 [
                          Res: C_TRUE
                        ][
                          Res: C_FALSE
                        ]
                      ]
                    ]
                  ][
                    either HeavyAtoms < 12.5000 [
                      Res: C_FALSE
                    ][
                      either Angles < 39.5000 [
                        Res: C_TRUE
                      ][
                        either Torsions < 14.5000 [
                          Res: C_FALSE
                        ][
                          either HeavyAtoms < 16.5000 [
                            either ChiralAtms < 1.5000 [
                              Res: C_FALSE
                            ][
                              Res: C_TRUE
                            ]
                          ][
                            Res: C_TRUE
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ][
            either Vdiam < 7.3000 [
              Res: C_FALSE
            ][
              either Sas < 561.9500 [
                either HeavyAtoms < 19.5000 [
                  either Torsions < 19.5000 [
                    if FG_COOH == C_FG_COOH_YES [
                      Res: C_FALSE
                    ][
                      Res: C_TRUE
                    ]
                  ][
                    Res: C_TRUE
                  ]
                ][
                  Res: C_TRUE
                ]
              ][
                Res: C_FALSE
              ]
            ]
          ]
        ][
          either Ovality < 1.6900 [
            either HbAcc < 3.5000 [
              either Rings < 1.5000 [
                Res: C_FALSE
              ][
                either Mass < 303.4100 [
                  either Ovality < 1.5900 [
                    Res: C_FALSE
                  ][
                    Res: C_TRUE
                  ]
                ][
                  Res: C_FALSE
                ]
              ]
            ][
              either Mass < 356.3800 [
                Res: C_FALSE
              ][
                either EzBnds < 0.5000 [
                  Res: C_FALSE
                ][
                  either Mass < 362.3900 [
                    Res: C_TRUE
                  ][
                    Res: C_FALSE
                  ]
                ]
              ]
            ]
          ][
            either Sdiam < 10.9700 [
              either Lipole < 2.3800 [
                either HbAcc < 3.5000 [
                  Res: C_TRUE
                ][
                  Res: C_FALSE
                ]
              ][
                Res: C_FALSE
              ]
            ][
              either VirtualLogP < 3.4100 [
                either Dipole < 2.8300 [
                  Res: C_FALSE
                ][
                  Res: C_TRUE
                ]
              ][
                Res: C_TRUE
              ]
            ]
          ]
        ]
      ][
        either FlexTorsions < 1.0000 [
          Res: C_TRUE
        ][
          either Ovality < 1.7300 [
            Res: C_FALSE
          ][
            either Psa < 59.6600 [
              either HeavyAtoms < 31.0000 [
                either Bonds < 51.5000 [
                  Res: C_FALSE
                ][
                  Res: C_TRUE
                ]
              ][
                either FlexTorsions < 9.0000 [
                  Res: C_FALSE
                ][
                  Res: C_TRUE
                ]
              ]
            ][
              if FG_PhOH == C_FG_PHOH_YES [
                either Angles < 119.5000 [
                  Res: C_TRUE
                ][
                  either Angles < 230.0000 [
                    Res: C_FALSE
                  ][
                    either ChiralAtms < 21.5000 [
                      Res: C_FALSE
                    ][
                      Res: C_TRUE
                    ]
                  ]
                ]
              ][
                if FG_F == C_FG_F_YES [
                  either ChiralAtms < 1.5000 [
                    Res: C_TRUE
                  ][
                    either Vdiam < 9.0700 [
                      Res: C_FALSE
                    ][
                      Res: C_TRUE
                    ]
                  ]
                ][
                  either Lipole < 2.3100 [
                    either FlexTorsions < 8.5000 [
                      either Sas < 977.1200 [
                        either EzBnds < 0.5000 [
                          either ChiralAtms < 0.5000 [
                            either Mass < 441.2400 [
                              Res: C_TRUE
                            ][
                              Res: C_FALSE
                            ]
                          ][
                            Res: C_FALSE
                          ]
                        ][
                          either Bonds < 59.0000 [
                            Res: C_FALSE
                          ][
                            Res: C_TRUE
                          ]
                        ]
                      ][
                        Res: C_TRUE
                      ]
                    ][
                      Res: C_FALSE
                    ]
                  ][
                    Res: C_FALSE
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]

    Res
  ]


  ;**** Domain check method ****

  ;
  ; Return the number of domain violations
  ;

  DomCheck: does [
    Violations: 0

    if any [Angles < 6.00000000 Angles > 374.00000000] [Violations: Violations + 1]
    if any [Atoms < 5.00000000 Atoms > 203.00000000] [Violations: Violations + 1]
    if any [Bonds < 4.00000000 Bonds > 206.00000000] [Violations: Violations + 1]
    if any [ChiralAtms < 0.00000000 ChiralAtms > 25.00000000] [Violations: Violations + 1]
    if any [Dipole < 0.00001200 Dipole > 22.36607000] [Violations: Violations + 1]
    if any [EzBnds < 0.00000000 EzBnds > 7.00000000] [Violations: Violations + 1]
    if any [FlexTorsions < 0.00000000 FlexTorsions > 28.00000000] [Violations: Violations + 1]
    if any [Gyrrad < 1.41856400 Gyrrad > 10.56297000] [Violations: Violations + 1]
    if any [HbAcc < 0.00000000 HbAcc > 26.00000000] [Violations: Violations + 1]
    if any [HbDon < 0.00000000 HbDon > 21.00000000] [Violations: Violations + 1]
    if any [HeavyAtoms < 3.00000000 HeavyAtoms > 101.00000000] [Violations: Violations + 1]
    if any [Lipole < 0.00000300 Lipole > 6.34667600] [Violations: Violations + 1]
    if any [Mass < 70.08984000 Mass > 1449.25400000] [Violations: Violations + 1]
    if any [Ovality < 1.16274900 Ovality > 2.74024100] [Violations: Violations + 1]
    if any [Psa < 0.00000000 Psa > 544.81690000] [Violations: Violations + 1]
    if any [Rings < 0.00000000 Rings > 10.00000000] [Violations: Violations + 1]
    if any [Sas < 203.40610000 Sas > 2006.11400000] [Violations: Violations + 1]
    if any [Sav < 252.97150000 Sav > 3811.29900000] [Violations: Violations + 1]
    if any [Sdiam < 5.14906200 Sdiam > 22.48208000] [Violations: Violations + 1]
    if any [Torsions < 0.00000000 Torsions > 94.00000000] [Violations: Violations + 1]
    if any [Vdiam < 4.77512900 Vdiam > 13.58132000] [Violations: Violations + 1]
    if any [VirtualLogP < -7.13032600 VirtualLogP > 9.48374900] [Violations: Violations + 1]

    Violations
  ]
]
